[Redis-6.0.8] Introduction to Redis source code analysis

table of Contents

1. Source code overview

1.1 Extract under the src folder

1.2 Core code distribution

1.2.1 Basic data structure

1.2.2 The underlying implementation of Redis data types

1.2.3 Implementation of Redis Database

1.2.4 Redis server and client implementation

1.2.5 Other

2. Some small attempts to read

2.1 The starting point of the server

2.2 The key steps of the server

2.2.1 setlocale

2.2.2 Set the callback function for memory overflow

2.2.3 Initialize the cyclic redundancy check table crc64_table of the static area

3. Initial experience of code debugging


1. Source code overview

1.1 Extract under the src folder

This picture is quoted from section 1.3 in "Redis5 Design and Source Code Analysis". server.c is the server program and redis-cli.c is the client program

1.2 Core code distribution

1.2.1 Basic data structure

(1)动态字符串sds.c
(2)整数集合intset.c
(3)压缩列表ziplist.c
(4)快速链表quicklist.c
(5)字典dict.c
(6)Streams的底层实现结构listpack.c和rax.c

1.2.2 The underlying implementation of Redis data types

(1)Redis对象object.c
(2)字符串t_string.c
(3)列表t_list.c
(4)字典t_hash.c
(5)集合及有序集合t_set.c和t_zset.c
(6)数据流t_stream.c

1.2.3 Implementation of Redis Database

(1)数据库的底层实现db.c
(2)持久化rdb.c和aof.c

1.2.4 Redis server and client implementation

(1)事件驱动ae.c和ae_epoll.c
(2)网络连接anet.c和networking.c
(3)服务端程序server.c
(4)客户端程序redis-cli.c

1.2.5 Other

(1)主从复制replication.c
(2)哨兵sentinel.c
(3)集群cluster.c
(4)其他数据结构,如hyperloglog.c、geo.c等
(5)其他功能,如pub/sub、Lua脚本

2. Some small attempts to read

2.1 The starting point of the server

D:\005-01-code\001-open source project source code\007-redis\redis-6.0.8.tar\redis-6.0.8\redis-6.0.8\src\server.c in the main function

2.2 The key steps of the server

2.2.1 setlocale

The role of setlocale() function

2.2.2 Set the callback function for memory overflow

zmalloc_set_oom_handler (redisOutOfMemoryHandler);

2.2.3 Initialize the cyclic redundancy check table crc64_table of the static area

 crc64_init();

3. Initial experience of code debugging

cd /home/muten/module/redis-6.0.9/src(仅仅是我的机器上)
gdb ./redis-server
>l server.c:5097,server.c:5150
>r
>i thread
>thread 1
>bt
>thread 2
>bt
>thread 3
>bt
>thread 4
>bt

Guess you like

Origin blog.csdn.net/Edidaughter/article/details/115264739