Redis 基本特性
1. 非关系型的键值对数据库,可以根据键以O(1) 的时间复杂度取出或插入关联值
2. Redis 的数据是存在内存中的
3. 键值对中键的类型可以是字符串,整型,浮点型等,且键是唯一的
4. 键值对中的值类型可以是string,hash,list,set,sorted set 等
5. Redis 内置了复制,磁盘持久化,LUA脚本,事务,SSL, ACLs,客户端缓存,客户端代理等功能
6. 通过Redis哨兵和Redis Cluster 模式提供高可用性
RedisDb 数据结构
typedef struct redisDb {
dict *dict;
dict *expires;
dict *blocking_keys;
dict *ready_keys;
dict *watched_keys;
int id;
long long avg_ttl;
unsigned long expires_cursor;
list *defrag_later;
} redisDb;
typedef struct dict {
dictType *type;
void *privdata;
dictht ht[2];
long rehashidx;
unsigned long iterators;
} dict;
typedef struct dictht {
dictEntry **table;
unsigned long size;
unsigned long sizemask;
unsigned long used;
} dictht;
typedef struct dictEntry {
void *key;
union {
void *val;
uint64_t u64;
int64_t s64;
double d;
} v;
struct dictEntry *next;
} dictEntry;
typedef struct redisObject {
unsigned type:4;
unsigned encoding:4;
unsigned lru:LRU_BITS;
int refcount;
void *ptr;
} robj;
String数据结构:
List数据结构:
Hash数据结构:
SkipList:
ZipList:
待完善!!!