#The redis source code is in ANSI C language. First of all, of course you should start reading from the main function. But we should grasp one main thread when reading, that is, when we enter a command to Redis, how the code is executed step by step. (Recommended Learning: Redis Video Tutorial )
This way we can observe from the outside and try to execute some commands. After understanding the external performance of these commands Go in and see how the corresponding source code is implemented. To understand these codes, we first need to understand the event mechanism of Redis.
Moreover, once we understand the mechanism of Redis' event loop (Event Loop), we will also understand an interesting question: Why can Redis be executed in a single thread but can handle multiple requests at the same time? (Of course, strictly speaking, Redis does not run with only one thread, but in addition to the main thread, other threads of Redis only play an auxiliary role. They are threads that run in the background to do asynchronous time-consuming tasks)
From Starting from the main function, we can actually follow the code execution path. Let’s limit the scope.
Start from the main function, follow it step by step, and finally reach the execution entrance of any Redis command. Or, you can complete the rest of the exploration on your own.
Overview of initialization process and event loop
The main function of the Redis source code is in the source file server.c. The logic after the main function starts executing can be divided into two stages:
Various initializations (including the initialization of the event loop);
Execution of the event loop.
These two execution stages can be expressed by the flow chart below (click to enlarge the image)
The above is the detailed content of What language is the redis source code?. For more information, please follow other related articles on the PHP Chinese website!