Hello everyone, today I would like to introduce my new book, Redis Core Principles and Practice. Backend development students should be familiar with Redis, Redis due to high performance, powerful, has become a very popular in-memory database industry.

“Redis Core Principles and Practices” this book in-depth analysis of Redis common features of the internal mechanism and implementation of the way, most of the content from the Redis source code analysis, and summed up the implementation principle. The inner workings of Redis can be quickly and easily understood by reading this book.

Why did you write this book?

I have been hoping to deeply analyze a C language implementation of distributed system procedures from the source level. Here’s why:

(1) C language can be said to be the closest to the low-level language development language, analysis of C language programs, we can better understand the underlying knowledge of the operating system.

(2) With the development of the Internet industry, the requirements for high availability and high performance of back-end systems are becoming higher and higher, and distributed systems are becoming more and more popular. Analyzing the design and implementation of a distributed system is of great help to our work and study.

So, I read and learned Redis source code, and wrote the “Redis core Principles and practice” this book.

Why Redis? Because Redis is typically a “small but beautiful” application.

Redis is simple, the source code is very elegant and concise, reading is not difficult, and Redis is fully functional, covering data storage, distributed, message flow and many other features, is worth in-depth learning.

Through writing this book, I have a better understanding of Redis, Unix programming, distributed system, storage system, and other related systems (such as Mysql, Nginx, Kafka). I can also draw inferential conclusions by analogy. I hope this book can help readers make further progress.

Structure of the book

The first part mainly analyzes the encoding format of five data types in Redis: string, hash, list, set and ordered set. Encoding format, that is, data storage format, for database, data storage format is very important, such as relational database row storage and column storage. While Redis as a memory database, the overall design idea for data coding is: maximum “time for space”, so as to maximize memory savings. This section details how Redis’s memory usage has become “penny-pinching.”

The second part analyzes the core process of Redis, including Redis event mechanism and command execution process. Redis uses the IO reuse model to implement its own event loop mechanism, which is being driven by Redis (many remote services use similar architectures, such as Nginx, Mysql, etc.). Redis event mechanism is elegant in design, simple in implementation, and excellent in performance, which can be said to “simplify the complex”.

The third part analyzes Redis persistence and replication mechanism. Although Redis is an in-memory database, it still maximizes the reliability of data. Whether it’s file persistence or replication from a node, the core idea is the same: keep your data secure by copying it to multiple copies. This part analyzes RDB, AOF persistence mechanism, master/slave node replication process and so on, showing readers how Redis data is “spread like wildfire”.

The fourth part analyzes Redis distributed architecture. Starting with Raft, a popular distributed algorithm, Sentient looks at how nodes are monitored by Sentient, how clusters are sharded, how they dynamically add and remove Cluster nodes, and what they do best: failover. Distributed systems often remind me of an interesting term, tiezulai (think of cluster nodes as “boats” and network connections between nodes as “cables”).

The fifth part analyzes the advanced features of Redis, including Redis transactions, non-blocking delete, ACL permission control list, Tracking mechanism, Lua script, Module Module, Stream message flow, etc., and provides detailed use cases to help readers learn and understand gradually from shallow to deep. Redis provides comprehensive support for a wide range of high performance, high availability scenarios.

This book features

This book is an in-depth analysis of how Redis is implemented, not an introduction to Redis. In order to reduce the difficulty of reading this book, this book summarizes the realization mechanism of each core function of Redis, extracts the core code of Redis (this book will try to avoid stacking code), and analyzes the source code and implementation principle of Redis in detail with appropriate pictures and texts, showing the design idea of the core function of Redis to the reader and the implementation process. Although most of the book is based on Redis source code analysis, it is not complicated and can be easily read even if you only have a brief understanding of the basic syntax of C.

Recommended reasons

  • New version: Based on Redis 6.0.9, Redis 6 features such as ACL, Tracking, I/O threads, etc.
  • Practice: This book provides detailed application examples on the basis of corresponding knowledge points to help readers learn and understand the new features of Redis from shallow to deep.
  • Easy to master: this book summarizes the realization principle of each core function of Redis, and with appropriate graphics, rich examples, the source code of Redis and its implementation principle are analyzed in detail, step by step to show the reader the design idea and implementation process of the core function of Redis. Readers can also read the Redis source code in conjunction with this book.
  • Rich content: this book not only analyzes the functions of Redis, but also by Redis source extended the following two aspects of content: (1) a detailed introduction to the Unix mechanism used in Redis, including Unix network programming, process (thread) application and other content, and through the source shows how Redis to use these Unix mechanisms. (2) Deeply analyze how Redis realizes a distributed system, mainly how Sentinel and Cluster mechanism realizes a highly available distributed system.

Due to my limited ability, there are inevitably omissions or mistakes in this book. If you have any questions or suggestions during reading this book, please feel free to communicate with us. I will sort out and give feedback to your questions and suggestions, and make corrections and updates in the subsequent editions of this book in time.

With the consent of the editor of this book, I will publish some chapters in the book on the personal technology official account (Binecy) later. As the preview content of the book, you are welcome to check it out. Thank you.

Jingdong link douban link