数据库
首页 > 数据库> > Redis系列2-Redis底层数据结构

Redis系列2-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 *ready_keys;           /* Blocked keys that received a PUSH */
    dict *watched_keys;         /* WATCHED keys for MULTI/EXEC CAS */
    int id;                     /* Database ID */
    long long avg_ttl;          /* Average TTL, just for stats */
    unsigned long expires_cursor; /* Cursor of the active expire cycle. */
    list *defrag_later;         /* List of key names to attempt to defrag one by one, gradually. */
} redisDb;

RedisObject

typedef 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;
} robj;

7种type

  1. 字符串对象sds
    Redis 使用了 SDS(Simple Dynamic String)。用于存储字符串和整型数据。
  2. 跳跃表skiplist
  3. 字典dict
  4. 压缩列表ziplist
  5. 整数集合intset
  6. 快速列表quicklist
  7. 流对象stream

10种encoding

  1. intset
  2. hashtable
  3. int
  4. embstr
  5. raw
  6. quicklist
  7. ziplist
  8. skiplist

标签:keys,refcount,Redis,unsigned,对象,dict,数据结构,底层
来源: https://www.cnblogs.com/mingpingyao/p/15230515.html