首页 > 其他 > 详细

读REDIS数据结构

时间:2014-07-06 13:54:12      阅读:319      评论:0      收藏:0      [点我收藏+]

一.DICT

主要有两个问题:

1.散列冲突,解决办法是拉链法

typedef struct dictEntry {
    void *key;
    union {
        void *val;
        uint64_t u64;
        int64_t s64;
    } v;
    struct dictEntry *next;
} dictEntry;

next字段向后拉链

2.扩容时候的rehash,做类似于copy on write

typedef struct dict {
    dictType *type;
    void *privdata;
    dictht ht[2];
    int rehashidx; /* rehashing not in progress if rehashidx == -1 */
    int iterators; /* number of iterators currently running */
} dict;

ht[0] 是存储了没扩容时候的数据,ht[1]存储扩容以后的数据。如果在需要扩容的时候,任何对哈希表的操作都会从ht[0]中找到一个key rehash以后放到ht[1],逐渐把ht[0]中的数据放到ht[1],当ht[0]中全部rehash完以后,释放空间,ht[0]指向ht[1]。

 

读REDIS数据结构,布布扣,bubuko.com

读REDIS数据结构

原文:http://www.cnblogs.com/23lalala/p/3825775.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!