Redis is one of the most widely used nosql products. The current stable version is 2.6.10, including GitHub, Instagram, blizzard, and Sina Weibo. redis is widely used in products. ItsCodeBased on the BSD Protocol open source, the entire project has only over 20 thousand lines of code (Version 2.2 ), you can read the code to learn the author's design philosophy and the implementation of redis in a relatively short period of time, so that you can understand it.
Today, huangz released the open-source document redis design and implementation.Source codeI started to learn about the redis notes collection. For the purpose of writing this document, the author said:
The goal of this book is to explain the internal operation mechanism of redis in a concise and easy-to-understand manner. by reading this book, you can understand almost all the knowledge of redis from data structures to server structures.
Redis design and implementation describes the implementation of redis in five aspects:
- Internal Data Structure
- Memory ing Data Structure
- Redis Data Type
- Function implementation
- Some Operating Mechanisms
At the same time, the author also gives a detailed comment on the source code of redis 2.6 to meet the needs of deep learning.
Huang jianhong (huangz), author of redis design and implementation, is a 90-Year-Old user who prefers functional programming. He began to read redis source code only when he was interested in the database, he looks at the entire reading process as follows:
Reading redis source code is a brand new learning experience for me. When I first looked at the redis source code, I only had some basic data structures andAlgorithmWithout any experience in network programming, database, or system programming, it is basically just a matter of looking at the source code while supplementing the basic knowledge.
When asked how to read the source code of an open-source project, he shared his methods:
Bottom-up: read from the module with the smallest coupling relationship, and then gradually over to the closely related module. It's like writingProgramThe unit test starts before the function test. When I first started reading the redis source code, I used this method: first starting from a separate data structure module, and then transitioning to a high-level functional module.
Start with the function: Quickly locate the specific implementation of a function through the file name (Module name) and function name, and then track the entire implementation process to learn how this function is implemented. This method is used when I read a blocking list, database, and other modules that are more coupled with other files.
Top-down: from the main () function of the program, or a very large caller function as the entry, read its source code in depth-first or breadth-first mode. I am reading redis. c/servercron (), redis. c/main () and AE. this method is used when C/aemain () is a function with obvious caller nature.
Then he stressed:
These three methods do not conflict with each other: some functions/modules must use some method, while some functions/modules must use another method, and sometimes multiple methods need to be mixed.
It is worth mentioning that this book has been open-source in the form of "reserve all rights". You can view the content creation process on GitHub, at the same time, this open-source collaboration method allows more people to participate in content optimization.
original address: http://www.infoq.com/cn/news/2013/03/redis-book