redis 的内存存储结构示意图
redisDb 的定义:
typedef struct redisDb{dict *dict; /* The keyspace for this DB */dict *expires; /* Timeout of keys with a timeout set */dict *blocking_keys; /* Keys with clients waiting for data (BLPOP) */dict *io_keys; /* Keys with clients waiting for VM I/O */dict *watched_keys; /* WATCHED keys for MULTI/EXEC CAS */int>} redisDb;redisDb 中 ,dict 成员是与实际存储数据相关的. dict 的定义如下:typedef struct dictEntry{void *key;void *val;struct dictEntry *next;} dictEntry;typedef struct dictType{unsigned int (*hashFunction)(const void *key);void *(*keyDup)(void *privdata, const void *key);void *(*valDup)(void *privdata, const void *obj);int (*keyCompare)(void *privdata, const void *key1, const void *key2);void (*keyDestructor)(void *privdata, void *key);void (*valDestructor)(void *privdata, void *obj);} dictType;/* This is our hash table structure. Every dictionary has two of this as we* implement incremental rehashing, for the old to the new table. */typedef struct dictht{dictEntry **table;unsigned long>unsigned long>unsigned long used;} dictht;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;