redisObject结构
对于 Redis的键值对来说,key一定是一个字符串(sds,也是一个redisObject)对象,而value则可以是五种对象的其中一种。
typedef struct redisObject {
unsigned type:4;//对象的数据类型 4位
unsigned encoding:4;//数据类型具体是哪种编码 4位
unsigned lru:REDIS_LRU_BITS; /* lru time (relative to server.lruclock) */ //lru记录此对象最后一次访问的时间 24位 16 + 8
int refcount;//引用次数
void *ptr;//真实指向的数据具体是
} robj;
type:
#define REDIS_STRING 0 字符串
#define REDIS_LIST 1 list 列表
#define REDIS_SET 2 set 集合
#define REDIS_ZSET 3 zset 有序集合
#define REDIS_HASH 4 hash 哈希
encoding
#define REDIS_ENCODING_RAW 0 /* Raw representation */
#define REDIS_ENCODING_INT 1 /* Encoded as integer */
#define REDIS_ENCODING_HT 2 /* Encoded as hash table */
#define REDIS_ENCODING_ZIPMAP 3 /* Encoded as zipmap */
#define REDIS_ENCODING_LINKEDLIST 4 /* Encoded as regular linked list */
#define REDIS_ENCODING_ZIPLIST 5 /* Encoded as ziplist */
#define REDIS_ENCODING_INTSET 6 /* Encoded as intset */
#define REDIS_ENCODING_SKIPLIST 7 /* Encoded as skiplist */
借用网上找到的一张好图: