最新redis6.2.6源码目录结构如下:
$ tree -L 2 -F
.
├── 00-RELEASENOTES*
├── BUGS*
├── CONDUCT*
├── CONTRIBUTING*
├── COPYING*
├── INSTALL*
├── MANIFESTO*
├── Makefile*
├── README.md*
├── TLS.md*
├── deps/ #第三方依赖目录
│ ├── Makefile*
│ ├── README.md*
│ ├── hdr_histogram/
│ ├── hiredis/ #client相关
│ ├── jemalloc/ #内存管理
│ ├── linenoise/ #命令行编辑库,readline的替代品
│ ├── lua/ # lua解释器
│ └── update-jemalloc.sh*
├── redis.conf* # redis配置文件
├── runtest*
├── runtest-cluster*
├── runtest-moduleapi*
├── runtest-sentinel*
├── sentinel.conf* # 哨兵配置文件
├── src/ # 主要源代码目录
│ ├── Makefile*
│ ├── acl.c* #权限控制
│ ├── adlist.c* # 双向链表
│ ├── adlist.h*
│ ├── ae.c* # 事件模型
│ ├── ae.h*
│ ├── ae_epoll.c* # epoll
│ ├── ae_evport.c* #evport
│ ├── ae_kqueue.c* #kqueue
│ ├── ae_select.c* #select
│ ├── anet.c* # 网络
│ ├── anet.h*
│ ├── aof.c* # append only file
│ ├── asciilogo.h* # ascii图标
│ ├── atomicvar.h*
│ ├── bio.c* # background io
│ ├── bio.h*
│ ├── bitops.c* # 位操作
│ ├── blocked.c*
│ ├── childinfo.c*
│ ├── cli_common.c*
│ ├── cli_common.h*
│ ├── cluster.c* # 集群
│ ├── cluster.h*
│ ├── config.c* #配置
│ ├── config.h*
│ ├── connection.c* #网络链接
│ ├── connection.h*
│ ├── connhelpers.h*
│ ├── crc16.c* #crc16 校验
│ ├── crc16_slottable.h*
│ ├── crc64.c* #crc64
│ ├── crc64.h*
│ ├── crcspeed.c*
│ ├── crcspeed.h*
│ ├── db.c* #db数据库操作
│ ├── debug.c* #调试
│ ├── debugmacro.h*
│ ├── defrag.c*
│ ├── dict.c* #hash操作
│ ├── dict.h*
│ ├── endianconv.c* #大小端转换
│ ├── endianconv.h*
│ ├── evict.c* #数据淘汰操作
│ ├── expire.c* #数据过期操作
│ ├── fmacros.h*
│ ├── geo.c* # geo
│ ├── geo.h*
│ ├── geohash.c*
│ ├── geohash.h*
│ ├── geohash_helper.c*
│ ├── geohash_helper.h*
│ ├── gopher.c*
│ ├── help.h*
│ ├── hyperloglog.c* #hyperloglog
│ ├── intset.c* #整数集合
│ ├── intset.h*
│ ├── latency.c* #延迟监控
│ ├── latency.h*
│ ├── lazyfree.c* #懒释放
│ ├── listpack.c* # listpack
│ ├── listpack.h*
│ ├── listpack_malloc.h*
│ ├── localtime.c*
│ ├── lolwut.c*
│ ├── lolwut.h*
│ ├── lolwut5.c*
│ ├── lolwut6.c*
│ ├── lzf.h*
│ ├── lzfP.h*
│ ├── lzf_c.c* #压缩算法
│ ├── lzf_d.c*
│ ├── memtest.c*
│ ├── mkreleasehdr.sh*
│ ├── module.c* #模块
│ ├── modules/ #模块目录,里面为一个简单的module开发例子
│ ├── monotonic.c* #单调时间
│ ├── monotonic.h*
│ ├── mt19937-64.c*
│ ├── mt19937-64.h*
│ ├── multi.c* #事务
│ ├── networking.c* #网络数据读写
│ ├── notify.c* #事件通知
│ ├── object.c* #对象
│ ├── pqsort.c*
│ ├── pqsort.h*
│ ├── pubsub.c* #发布订阅
│ ├── quicklist.c* #快速双向链表
│ ├── quicklist.h*
│ ├── rand.c*
│ ├── rand.h*
│ ├── rax.c* #基数树
│ ├── rax.h*
│ ├── rax_malloc.h*
│ ├── rdb.c* # rdb持久化
│ ├── rdb.h*
│ ├── redis-benchmark.c* #性能测试
│ ├── redis-check-aof.c* #aof文件完整性校验
│ ├── redis-check-rdb.c* #rdb文件完整性校验
│ ├── redis-cli.c* #redis客户端
│ ├── redis-trib.rb*
│ ├── redisassert.h*
│ ├── redismodule.h*
│ ├── release.c*
│ ├── replication.c* #主从复制
│ ├── rio.c* #rdb文件读写
│ ├── rio.h*
│ ├── scripting.c* #脚本处理
│ ├── sds.c* #sds字符串
│ ├── sds.h*
│ ├── sdsalloc.h*
│ ├── sentinel.c* #哨兵
│ ├── server.c* #主框架
│ ├── server.h*
│ ├── setcpuaffinity.c* #设置cpu亲核性
│ ├── setproctitle.c* #设置进程名
│ ├── sha1.c*
│ ├── sha1.h*
│ ├── sha256.c*
│ ├── sha256.h*
│ ├── siphash.c*
│ ├── slowlog.c* #慢日志
│ ├── slowlog.h*
│ ├── solarisfixes.h*
│ ├── sort.c*
│ ├── sparkline.c*
│ ├── sparkline.h*
│ ├── stream.h* #stream消息队列
│ ├── syncio.c* #同步io
│ ├── t_hash.c*
│ ├── t_list.c*
│ ├── t_set.c*
│ ├── t_stream.c*
│ ├── t_string.c*
│ ├── t_zset.c*
│ ├── testhelp.h*
│ ├── timeout.c*
│ ├── tls.c* #加密传输
│ ├── tracking.c*
│ ├── util.c*
│ ├── util.h*
│ ├── valgrind.sup*
│ ├── version.h*
│ ├── ziplist.c* #压缩列表
│ ├── ziplist.h*
│ ├── zipmap.c* #压缩map
│ ├── zipmap.h*
│ ├── zmalloc.c* #内存分配
│ └── zmalloc.h*
├── tests/ #测试目录
│ ├── assets/
│ ├── cluster/ #集群
│ ├── helpers/
│ ├── instances.tcl*
│ ├── integration/ #数据迁移
│ ├── modules/ #模块
│ ├── sentinel/ #哨兵
│ ├── support/
│ ├── test_helper.tcl*
│ ├── tmp/
│ └── unit/ #单元测试
└── utils/ #工具库目录
├── build-static-symbols.tcl*
├── cluster_fail_time.tcl*
├── corrupt_rdb.c*
├── create-cluster/ #创建集群
├── gen-test-certs.sh*
├── generate-command-help.rb*
├── graphs/
├── hashtable/
├── hyperloglog/
├── install_server.sh*
├── lru/ #lru相关
├── redis-copy.rb*
├── redis-sha1.rb*
├── redis_init_script*
├── redis_init_script.tpl*
├── releasetools/
├── speed-regression.tcl*
├── srandmember/
├── systemd-redis_multiple_servers@.service*
├── systemd-redis_server.service*
├── tracking_collisions.c*
└── whatisdoing.sh*
26 directories, 184 files
一、目录
目录名 | 描述 | 子目录 |
---|---|---|
deps | 第三方依赖库 | hdr_histogram(直方图), hiredis(redis客户端C),jemalloc(内存管理),linenoise(命令行编辑库),lua(lua解释器) |
test | 测试目录 | unit(单元测试),cluster(集群模块测试),sentinel(哨兵模块测试),modules(so测试),intergration(主从复制测试)… |
utils | 辅助线功能代码 | create-cluster(集群创建),hashtable,lru, graphs,hyperloglog,releasetools,srandmember |
src | 主要功能模块 | modules(样例代码) |
二、src
2.1 主代码
server.c 、server.h
2.2 配置处理
config.c 、config.h
2.3 事件驱动
ae.c、 ae.h
2.4 io多路复用
ae_epoll.c
ae_evport.c
ae_kqueue.c
ae_select.c
2.5 网络
anet.c、 anet.h
connection.c、 connection.h
networking.c
2.6 数据库操作
db.c
2.7 数据淘汰
evict.c
2.8 数据过期
expire.c
2.9 懒释放
lazyfree.c
2.10 后台任务
bio.c、bio.h
2.11 数据持久化
aof.c
rdb.c、rdb.h
2.12 发布订阅
pubsub.c
2.13 事务
multi.c
2.14 主从
replication.c
2.15 哨兵
sentinel.c
2.16 集群
cluster.c、cluster.h
2.17 慢日志
slowlog.c、slowlog.h
2.18 调试
debug.c
debugmacro.h
tracking.c
2.19 脚本
scripting.c
2.20 消息队列
t_stream.c
stream.h
2.21 其他
…
三、数据结构
3.1 string
sds.c、sds.h
sdsalloc.h
3.2 hash
dict.c、dict.h
zipmap.c、zipmap.h
ziplist.c、ziplist.h
quicklist.c、quicklist.h
3.3 集合
t_zset.c
intset.c、inset.h
3.4 双向链表
adlist.c、adlist.h
3.5 位图
bitops.c
3.6 基数树
rax.c、rax.h
3.7 geo
geo.c、geo.h
geohash.c、geohash.h
geohash_helper.c、geohash_helper.h
hyperloglog
hyperloglog.c