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;
- type:4位(bit),表示对象的类型
- encoding:4位(bit),表示对象的内部编码,Redis 可以根据不同的使用场景来为对象设置不同的编码,大大提高了 Redis 的灵活性和效率。
- lru: 24位(bit),高16位存储一个分钟数级别的时间戳,低8位存储访问计数(lfu : 最近访问次数)
- refcount: 记录的是该对象被引用的次数,类型为整型。refcount 的作用,主要在于对象的引用计数和内存回收。当对象的refcount>1时,称为共享对象
- ptr: 指针指向具体的数据
7种type
- 字符串对象sds
Redis 使用了 SDS(Simple Dynamic String)。用于存储字符串和整型数据。 - 跳跃表skiplist
- 字典dict
- 压缩列表ziplist
- 整数集合intset
- 快速列表quicklist
- 流对象stream
10种encoding
- intset
- hashtable
- int
- embstr
- raw
- quicklist
- ziplist
- skiplist
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。