Redis(Remote Dictionary Server)是一种开源的高效key-value存储系统,作者是Salvatore Sanfilippo。
使用C语言编写,遵循BSD协议。通常作为数据库、缓存和消息代理使用。Redis支持的存储数据结构包括string、hash map、list、set、bitmap、hyperloglogs和geospatial indexes。Redis有内建的主备机制、LRU机制、事务处理、持久化、集群方式、发布/订阅机制。以提供高效的,适用于多种场景的应用。
Redis的官网:https://redis.io/ ,官网中文翻译网址:http://www.redis.cn/
本系列主要从源码入手,分析Redis的设计和实现,使用的Redis版本是3.2.9
Redis的源码结构非常清晰,每个文件包含了单独的功能。从源码结构入手有助于理清Redis的逻辑。先列出源码的结构以供参考
|
分类1 |
分类2 |
分类3 |
头文件 |
C文件 |
|
基础封装 |
内存管理 |
|
sdsalloc.h |
|
|
|
zmalloc.h |
zmalloc.c |
||
|
|
|
memtest.c |
||
|
数据结构 |
|
sds.h |
sds.c |
|
|
adlist.h |
adlist.c |
|||
|
dict.h |
dict.c |
|||
|
quicklist.h |
quicklist.c |
|||
|
|
ziplist.h |
ziplist.c |
||
|
zipmap.h |
zipmap.c |
|||
|
intset.h |
intset.c |
|||
|
|
object.c |
|||
|
网络 |
事件驱动模型 |
ae.h |
ae.c |
|
|
|
ae_evport.c |
|||
|
|
ae_epoll.c |
|||
|
|
ae_kqueue.c |
|||
|
|
ae_select.c |
|||
|
anet.h |
anet.c |
|||
|
|
syncio.c |
|||
|
工具 |
|
util.h |
util.c |
|
|
|
endianconv.h |
endianconv.c |
||
|
|
rand.h |
rand.c |
||
|
|
sha1.h |
sha1.c |
||
|
冗余校验 |
|
crc16.c |
||
|
crc64.h |
crc64.c |
|||
|
压缩/解压缩 |
lzf.h |
lzf_c.c |
||
|
lzfP.h |
lzf_d.c |
|||
|
|
|
networking.c |
||
|
|
pqsort.h |
pqsort.c |
||
|
其他 |
|
debugmacro.h |
|
|
|
|
fmacros.h |
|
||
|
|
help.h |
|
||
|
|
testhelp.h |
|
||
|
|
version.h |
|
||
|
|
redisassert.h |
|
||
|
|
solarisfixes.h |
|
||
|
|
asciilogo.h |
|
||
|
|
|
debug.c |
||
|
实现 |
进程 |
|
|
redis-benchmark.c |
|
|
|
redis-check-aof.c |
||
|
|
|
redis-check-rdb.c |
||
|
|
|
redis-cli.c |
||
|
|
server.h |
server.c |
||
|
命令 |
|
|
db.c |
|
|
|
|
bitops.c |
||
|
|
|
t_hash.c |
||
|
|
|
t_list.c |
||
|
|
|
t_set.c |
||
|
|
|
t_string.c |
||
|
|
|
t_zset.c |
||
|
|
|
sort.c |
||
|
|
geo.h |
geo.c |
||
|
|
|
multi.c |
||
|
|
|
hyperloglog.c |
||
|
文件 |
|
rdb.h |
rdb.c |
|
|
|
bio.h |
bio.c |
||
|
|
rio.h |
rio.c |
||
|
多机 |
集群 |
cluster.h |
cluster.c |
|
|
主从 |
|
replication.c |
||
|
|
|
sentinel.c |
||
|
|
latency.h |
latency.c |
||
|
其他 |
通知 |
|
notify.c |
|
|
发布订阅 |
|
pubsub.c |
||
|
慢查询日志 |
slowlog.h |
slowlog.c |
||
|
|
|
blocked.c |
||
|
配置 |
config.h |
config.c |
||
|
封装脚本 |
|
scripting.c |
||
|
|
sparkline.h |
sparkline.c |
||
|
|
|
setproctitle.c |
简单说明:
基础封装:包括封装了专用的内存管理器、Redis数据结构(包括string、list、map、set等)、网络库和一些基础工具。
Redis实现:包括Redis命令,本地化、集群和一些其他功能。