码迷,mamicode.com
首页 > 其他好文 > 详细

redis 》List存储结构

时间:2021-06-02 18:11:23      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:head   nta   一个   元素   field   tor   class   pre   off   

redis的List存储结构:一个链表加上压缩列表实现的


技术图片

 

redis  c语言源码

双向循环列表


#   define QL_FILL_BITS 16
#   define QL_COMP_BITS 16
#   define QL_BM_BITS 4 /
typedef struct quicklist {
    quicklistNode *head; 头节点
    quicklistNode *tail; 尾节点
    unsigned long count;        /* total count of all entries in all ziplists */ ziplist里面存储的元素的数量
    unsigned long len;          /* number of quicklistNodes */ 节点数
    int fill : QL_FILL_BITS;              /* fill factor for individual nodes */ zplist挂在存在压缩列表的个数或者容量
    unsigned int compress : QL_COMP_BITS; /* depth of end nodes not to compress;0=off */ 节点的zip;ist是否压缩
    unsigned int bookmark_count: QL_BM_BITS;
    quicklistBookmark bookmarks[];
} quicklist;

技术图片
在每个quicklist里存储的很多个quicklistNod
/* quicklistNode is a 32 byte struct describing a ziplist for a quicklist.
 * We use bit fields keep the quicklistNode at 32 bytes.
 * count: 16 bits, max 65536 (max zl bytes is 65k, so max count actually < 32k).
 * encoding: 2 bits, RAW=1, LZF=2.
 * container: 2 bits, NONE=1, ZIPLIST=2.
 * recompress: 1 bit, bool, true if node is temporary decompressed for usage.
 * attempted_compress: 1 bit, boolean, used for verifying during testing.
 * extra: 10 bits, free for future use; pads out the remainder of 32 bits */

quicklistNode里面的存储 typedef struct quicklistNode { struct quicklistNode *prev; 上一个节点 struct quicklistNode *next;下一个节点 unsigned char *zl; 当前结点指针 unsigned int sz; 当前存储读诵好元素 /* ziplist size in bytes */ unsigned int count : 16; /* count of items in ziplist */ unsigned int encoding : 2; /* RAW==1 or LZF==2 */ unsigned int container : 2; /* NONE==1 or ZIPLIST==2 */ 选用一个ziplist unsigned int recompress : 1; /* was this node previous compressed? */ 启用压缩列表标记 unsigned int attempted_compress : 1; /* node can‘t compress; too small */ unsigned int extra : 10; /* more bits to steal for future usage */ } quicklistNode;

 

 

redis 》List存储结构

标签:head   nta   一个   元素   field   tor   class   pre   off   

原文地址:https://www.cnblogs.com/wangbiaohistory/p/14829568.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!