dict.h中的结构体
dictEntry结构体
1 | typedef struct dictEntry { |
dictType结构体
1 | /* 定义了字典操作的公共方法,类似于adlist.h文件中list的定义,将对节点的公共操作方法统一定义。搞不明白为什么要命名为dictType */ |
dictht结构体
1 | /* This is our hash table structure. Every dictionary has two of this as we |
dict结构体
1 | /* 字典的主操作类,对dictht结构再次包装 */ |
四个结构体之间的关系:

散列函数
- Thomas Wang’s 32 bit Mix
dictIntHashFunction,对整形取hash - MurmurHash2 by Austin Appleby
dictGenHashFunction,对key值与指定长度取hash - case insensitive hash function (based on djb hash)
dictGenCaseHashFunction对字符串进行hash
Rehash操作
- n步渐进式rehash操作,这是redis的一个亮点,能够将一次rehash分摊到多次数据请求中
_dictRehashStep,每调用一次Rehash一个bucketdictRehashMilliseconds在一定时间内rehash多个bucket- 上面两个函数都调用了
dictRehash方法:
1 | /* Performs N steps of incremental rehashing. Returns 1 if there are still |