基于Redis 6.0

redis实际对象头,会保存通用对象类型需要的元信息。

  1. 对象类型。
  2. 对象编码。
  3. lru time属性。
  4. 引用计数。
  5. 实际对象指针。
// src/server.h
struct redisObject {
    unsigned type:4;
    unsigned encoding:4;
    unsigned lru:LRU_BITS; /* LRU time (relative to global lru_clock) or
                            * LFU data (least significant 8 bits frequency
                            * and most significant 16 bits access time). */
    int refcount;
    void *ptr;
};