redis代码 支持的数据结构
2014-05-06 18:19
351 查看
String.................................... typedef char *sds; struct sdshdr { int len; int free; char buf[]; };//buf[]不占结构体shshdr的空间。 都是通过buf获取对应的sdshdr的指针,来获取其他成员len/free; 内存的申请和释放也是以sdshdr为申请单位。 Strings支持的操作类似char *; 有cat, cpy, dup, range(sub), cmp, trim等 static inline size_t sdslen(const sds s) { struct sdshdr *sh = (void*)(s-(sizeof(struct sdshdr)));/////////////s更前面是个头部, 包含len与free信息。 return sh->len; } static inline size_t sdsavail(const sds s) { struct sdshdr *sh = (void*)(s-(sizeof(struct sdshdr))); return sh->free; } hash table.......................................................................... typedef struct dictEntry { void *key; union { void *val; uint64_t u64; int64_t s64; } v; struct dictEntry *next; } dictEntry; typedef struct dictType { unsigned int (*hashFunction)(const void *key); void *(*keyDup)(void *privdata, const void *key); void *(*valDup)(void *privdata, const void *obj); int (*keyCompare)(void *privdata, const void *key1, const void *key2); void (*keyDestructor)(void *privdata, void *key); void (*valDestructor)(void *privdata, void *obj); } dictType; /* This is our hash table structure. Every dictionary has two of this as we * implement incremental rehashing, for the old to the new table. */ typedef struct dictht { dictEntry **table;//一维数组, 数组元素是dictEntry* 类型。 unsigned long size;//table数组的长度、桶个数 unsigned long sizemask;//size - 1用于 与hash(key) ^ sizemask, 得到的值将永远<=size unsigned long used;//总元素个数 } dictht; typedef struct dict { dictType *type;//hash计算中的一组函数指针。 void *privdata; dictht ht[2];//用于expand/rehash时的切换; int rehashidx; /* rehashing not in progress if rehashidx == -1 */ int iterators; /* number of iterators currently running */ } dict; 支持fetch/add/replace/find等操作 adlist, linked list....................................... add/insert/del/search typedef struct listNode { struct listNode *prev; struct listNode *next; void *value; } listNode; typedef struct listIter { listNode *next; int direction; } listIter; typedef struct list { listNode *head; listNode *tail; void *(*dup)(void *ptr); void (*free)(void *ptr); int (*match)(void *ptr, void *key); unsigned long len; } list;
redisServer 类似于数据库
redisServer::db[] 类似于数据库的db
redisServer::db->dict类似于table; dict中的<key, value>类似于表记录。 db只有1个dict。
rdb。。。。
rdbSaveBackground fork子进程, 在子进程内调用rdbSave遍历所有并 进行写文件。
aof。。。。优先级比rdb高。
类似于mysql的binlog
相关文章推荐
- Redis 支持的5种数据结构
- Redis支持的数据结构
- SSDB:一个高性能的支持丰富数据结构的 NoSQL 数据库, 用于替代 Redis
- redis是key-value存储的,放在内存中,并在磁盘持久化的数据结构存储系统 通过set key value来存储,通过get key来获取值 复制代码 set key value:设
- Redis 支持的5种数据结构
- redis命令支持复杂数据结构BST
- MDA框架生成代码流程和图例(UML 正向工程,支持Java, C#, Ansi C++, Delphi, Perl, Php5, Python, Database,Ruby, Hibern)
- Redis大鹏博客转载____(一)Redis几种数据结构
- C语言实现的统计php代码行数功能源码(支持文件夹、多目录)
- Redis海量数据java测试代码
- 支持firefox10和IE的上传预览图片js代码
- 发布NBearLite v1.0.0 beta - 全面支持SqlServer,Oracle,MySql,PostgreSql数据库存储过程调用代码生成(C#/VB.NET)
- Java编码规范,让你的代码赏心悦目--对象和数据结构
- 利用面向对象的思想实现一套代码,要求一个APP支持微信支付,支付宝支付,银联支付
- css的兼容性:IE6不支持max-width和min-height,应该如何写代码才能正常显示
- fixedBox固定div漂浮代码支持ie6以上大部分主流浏览器
- Redis数据结构-Hash
- [数据结构]程杰队列的链式存储结构及实现代码
- redis数据结构-跳跃表&整数集合&压缩列表
- SSM项目加入Redis支持