SDS,simple dynamic string
- 二进制安全的数据结构
- 空间换时间,每次扩容(len+addLen)*2进行内存预分配,当内存达到1M之后,扩容每次只能增加1M
- 兼容C数据的函数库
redis中所有的key都是string类型
struct sds{//redis会根据buf的大小动态的选择sds的类型int alloct;int len;uint8 flags;char[] buf;}
Dict
- 海量数据的存储:数组,链表
- hash(key)->自然数[大]
- 数组+链表,头插法
redisDb一共有15个
/* Redis database representation. There are multiple databases identified* by integers from 0 (the default database) up to the max configured* database. The database number is the 'id' field in the structure. */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 */} redisDb;
- 每个字典里面都有两个dictht,是因为redis里面采用了渐进式的rehash,不会一次性把数据数据全部转移到新的ht当中来
- dictEntry
redisObject:表示value中的类型,包括string,hash,set,zset,encoding表示实际存储的类型
String的编码类型
int
对于int范围之内且能够转换成一个整型值的value,直接通过*ptr保存(8个字节)
- embstr
一个redisObject总共16个字节,cacheLine是64字节,sdshdr8加上终结字符’/0’一共是4字节,所以剩余44个字节,只要字符串字节数少于44个字节就可以作为embstr

