源码分析
Aegeaner
这个作者很懒,什么都没留下…
展开
-
The architecture of REDIS
REDIS is an open source, advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets. Redis works with an in-memo转载 2012-02-01 16:33:53 · 2064 阅读 · 0 评论 -
Redis源代码分析之二:散列表——Dict(上)
先介绍Redis散列表实现的几个重要数据结构:字典项DictEntry:typedef struct dictEntry { void *key; void *val; struct dictEntry *next;} dictEntry;字典类型DictType:typedef struct dictType { unsigned原创 2012-02-01 20:16:48 · 3968 阅读 · 0 评论 -
Redis源代码分析之一:内存管理——Zmalloc
首先Zmalloc的接口定义在头文件Zmalloc.h里:void *zmalloc(size_t size);void *zcalloc(size_t size);void *zrealloc(void *ptr, size_t size);void zfree(void *ptr);char *zstrdup(const char *s);size_t zmalloc_use原创 2012-02-01 19:05:05 · 8634 阅读 · 1 评论 -
Redis源代码分析之三:散列表——Dict(下)
下面分析散列表常见操作,如插入、删除、替换等。散列表插入函数dictAdd实现如下:/* Add an element to the target hash table */int dictAdd(dict *d, void *key, void *val){ int index; dictEntry *entry; dictht *ht; if原创 2012-02-04 11:48:44 · 3084 阅读 · 0 评论 -
Redis源代码分析之五:简单动态字符串——Sds
一个Redis字符串的结构体定义是:struct sdshdr { int len; int free; char buf[];};其中buf字符数组中储存实际的字符串。len变量保存字符串的长度。free变量指出还有多少字节可用。sds被定义为一种新的数据类型,实际就是字符指针:typedef char *sds;例如,sdsnewlen原创 2012-02-04 15:40:27 · 2349 阅读 · 0 评论 -
Redis源代码分析之四:Unix底层网络通信——Anet
还是先介绍接口:int anetTcpConnect(char *err, char *addr, int port);int anetTcpNonBlockConnect(char *err, char *addr, int port);int anetUnixConnect(char *err, char *path);int anetUnixNonBlockConnect(ch原创 2012-02-04 14:29:33 · 4424 阅读 · 1 评论 -
【Redis】Why is an Event Library needed at all?
Let us figure it out through a series of Q&As.Q: What do you expect a network server to be doing all the time? A: Watch for inbound connections on the port its listening and accept them.Q: C转载 2012-02-04 15:05:34 · 1421 阅读 · 0 评论 -
Redis源代码分析之六:Redis执行流程
现在我们分析Redis从启动开始的执行流程,从而顺藤摸瓜地理解其事件驱动模型。首先找到main入口:int main(int argc, char **argv) { time_t start; initServerConfig(); if (argc == 2) { if (strcmp(argv[1], "-v") == 0 ||原创 2012-02-27 14:09:40 · 8674 阅读 · 0 评论 -
Redis源代码分析之七:事件驱动库分析——Ae
aeEventLoop是一个记录记录程序事件状态的结构:/* State of an event based program */typedef struct aeEventLoop { int maxfd; long long timeEventNextId; aeFileEvent events[AE_SETSIZE]; /* Registered events */原创 2012-02-27 15:12:49 · 5310 阅读 · 1 评论