Redis

1. sds类型

   sds为一种抽象数据结构 

typedef char *sds;
struct sdshdr {
 // buf 已占用长度
int len;
 // buf 剩余可用长度
int free;
 // 实际保存字符串数据的地方
char buf[];
};

 

2.sds的基本api

 

3. 双端链表

 

     

其中,listNode 是双端链表的节点:
typedef struct listNode {
// 前驱节点
struct listNode *prev;
// 后继节点
struct listNode *next;
// 值
void *value;
} listNode;

  而list 则是双端链表本身:

typedef struct list {
// 表头指针
listNode *head;
// 表尾指针
listNode *tail;
// 节点数量
unsigned long len;
// 复制函数
void *(*dup)(void *ptr);
// 释放函数
void (*free)(void *ptr);
// 比对函数
int (*match)(void *ptr, void *key);
} list;

4.双端链表的基本api

5.字典  

/*
* 字典
**
每个字典使用两个哈希表,用于实现渐进式rehash
*/
typedef struct dict {
// 特定于类型的处理函数
dictType *type;
// 类型处理函数的私有数据
void *privdata;
// 哈希表(2 个)
dictht ht[2];
// 记录rehash 进度的标志,值为-1 表示rehash 未进行
int rehashidx;
// 当前正在运作的安全迭代器数量
int iterators;
} dict;

6.字典API

  

 

posted @ 2016-12-23 16:26  fubst0318  阅读(84)  评论(0编辑  收藏  举报