Redis source code analysis (1) -- redis Structure Analysis

Source: Internet
Author: User
Tags redis version redis server

From today on, I will start learning redis source code. The redis code is relatively small and very suitable for learning. It is a very good learning material, it looks like about 100 files, which are written in C language. I hope I can finally get rid of him. I don't need the C language for a long time and I will forget it. The first step in source code analysis is to look at the source code structure from where to start. You can browse the source code structure in a modular manner, redis source code is all put in the src directory, and more than 90 files are all in it, so I chose to split by function, for some files, you can see what they do. After splitting, the result is as follows:


11 packages, so the files in each package are more acceptable, but it took me some time to separate the categories. I thought about some of the main file features in redis, finally, it should be relatively complete.

The following introduces a package:


Test: (test)
1. memtest. c memory Detection
2. redis_benchmark.c is used for redis performance testing.
3. redis_check_aof.c is used to update the Log check implementation.
4. redis_check_dump.c is used for local database check.
5. testhelp. C is a small C-style testing framework.


Struct: (struct)
1. adlist. C is used to define a list. It is a two-way linked list structure.
2. dict. c manages the hash in the memory.
3. SDS. C is used to define strings.
4. sparkline. c. a sequence with a sample list
5. The t_hash.c hash response operation in the server/client. Mainly through redisobject type conversion.
6. t_list.c list in the server/client. Mainly through redisobject type conversion.
7. t_set.c set in server/client. Mainly through redisobject type conversion.
8. t_string.c string response operation in the server/client. Mainly through redisobject type conversion.
9. t_zset.c zset in the server/client. Mainly through redisobject type conversion.
10.zip list. c ziplist is a storage object similar to list. The principle is similar to zipmap.
11.zip map. c zipmap is a storage object similar to hash.


Data: (Data Operations)
1. Aof. C is called append only file. It records every write operation and can be used to restore the database status in case of power failure or other problems.
2. config. C is used to put the properties read from the configuration file redis. conf in the configuration file into the server object through a program.
3. operations related to redis memory database in db. C.
4. multi. C is used for transaction processing.
5. RDB. C for redis local database operations, the default file is dump. Rdb (obtained through the configuration file), including Save, remove, query and so on.
6. Replication. C is used to implement master-slave database replication.


Tool: (Tool)
1. bitops. C-bit operation-related classes
2. Debug. c used for debugging
3. endianconv. C high/low bit conversion. Different systems have different high/low bit order.
4. Help. h assists with command prompts
5. lzf_c.c compression algorithm series
6. lzf_d.c compression algorithm series
7. Rand. C is used to generate random numbers.
8. Release. C is used for release.
9. sha1.c Sha Encryption Algorithm Implementation
10. util. c General tool Method
11. crc64.c Cyclic Redundancy Verification


Event: (Event)
1. AE. C is used to process redis events, including handle events and timeout events.
2. AE _epoll.c implements the epoll System Call Interface
3. AE _evport.c implements the evport System Call Interface
4. AE _kqueue.c implements the kqueuex system call interface.
5. AE _select.c implements the interface called by the Select system.


Baseinfo: (Basic Information)
1. asciilogo, C redis logo display
2. version. h must have the redis version number.


Compatible: (compatible)
1. Compatibility with Mac in fmacros. h
2. Problems Related to solarisfixes. h compatibility with solary


Main :( Main Program)
1. redis. c redis server program
2. redis_cli.c redis client program


Net: (network)
1. Anet. c is the basic encapsulation of server/client communication.
2. The networking. C network protocol transmission method definition is stored in this file.


Wrapper: (encapsulation class)
1. Bio. c background I/O indicates that
2. hyperloglog. C is a log type
3. Use set in the intset. c Integer Range and include related set operations.
4. latency. c latency class
5. migrate. C command migration class, including command restoration and migration
6. Notify. C Notification class
7. Object. C is used to create and release a redisobject object.
8. pqsort. c sorting algorithm class
9. pubsub. C is used to implement the subscription mode, which is somewhat similar to the client Broadcast Transmission Mode.
10. an I/O class defined by Rio. c redis
11. slowlog. C is a log type, similar to hyperloglog. C.
12. The sort. c sorting algorithm class is different from that used in pqsort. C.
13. syncio. C is used to synchronize socket and file I/O operations.
14. zmalloc. c encapsulation Implementation of redis Memory Allocation


Others :( stores some classes that I am not very clear yet, so I have not explained them)
1. Scripting. c
2. Sentinel. c
2. setproctitle. c
3. valgrind. Sh
4. redisassert. h

I analyzed this redis source code is currently the latest code redis-2.8.17, to ensure that it is the latest, new crc64.c and so on these in the version of about 2.2 does not have at all, there are a lot. the H header file has been saved because many of the same file names. H ,. the C file actually refers to the same function. In the future, I will analyze the redis source code in modules, and I will not have time to study the code level at work. Hurry up, fighting!


Redis source code analysis (1) -- redis Structure Analysis

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.