Extra Meal 01 Classic Redis Learning Materials

Extra Meal 01 Classic Redis Learning Materials #

The “Basic” part of our course has ended. In this module, we have learned about the core knowledge points of Redis such as its system architecture, data structure, thread model, persistence, master-slave replication, and sharding cluster. I believe you have built a basic knowledge framework for yourself.

However, if you want to continuously improve your technical skills and enrich your knowledge system, reading is a great way to do so. Therefore, in this lesson, I will recommend several excellent books and other supplementary materials to help you fully grasp Redis.

Books #

  • 《Redis设计与实现》:该书由Redis的作者——周立(阿里云工程师)编写,详细介绍了Redis的设计思想、源码分析以及常用功能的实现原理。适合有一定基础的读者,能够深入了解Redis的内部工作原理。
  • 《Redis 实战》:由Josiah L. Carlson撰写,是使用Redis构建实际应用的指南。书中包含了丰富的例子和实用技巧,适合希望深入了解如何使用Redis解决实际问题的读者。
  • 《Redis Cookbook》:由Tiago Cesar和Fred Oliveira合著,主要介绍了Redis的不同方面,从基本操作到高级用法都有涉及。通过该书,读者可以学习如何使用Redis来解决各种问题。
  • 《Redis in Action》:作者是Josiah L. Carlson,书中详细介绍了Redis的常见用途和应用场景。适合想要从实际案例中学习如何使用Redis的用户。

Other resources #

  • Redis 官方文档:Redis官方提供的英文文档包含了Redis的完整说明,从基础到高级用法都有详细介绍,对于想要全面了解Redis的读者来说是必备的参考资料。
  • Redis 应用大全:这是一个由介绍Redis常见应用场景和案例的开源项目,里面包含了大量的学习资源和实用工具,可以帮助你更好地应用Redis。

希望上述资料能够对你的Redis学习有所帮助!

Classic Books #

When studying Redis, there are three common requirements.

  • Daily operations: such as common commands and configurations, cluster setup, etc.
  • Key technical principles: such as the IO model, AOF, and RDB mechanisms that we have discussed before.
  • Lessons and experiences in practical applications, for example, what to do when Redis responds slowly or when the data between master and slave is inconsistent, etc.

Next, I will divide the reference materials into three categories: tools, principles, and practical applications, based on these needs. Let’s start by looking at the tools category.

Tools: “Redis Usage Manual” #

A good tool book can help us quickly understand or query the daily commands and operating methods of Redis. The “Redis Usage Manual” that I recommend is a very useful tool book.

In this book, the author divides the content of Redis into three parts: “Data Structures and Applications,” “Additional Functions,” and “Multiple Machine Functions.” Among them, I think the most useful part is the content of “Data Structures and Applications” because it provides a rich introduction to operation commands. It not only covers the main operation commands of the five basic data types in Redis but also introduces the command operations of four extended data types, including bitmaps, geospatial coordinates, HyperLogLog, and streams. With this book at hand, we can easily understand and correctly use most of the Redis operation commands.

However, if you want to understand the most complete and up-to-date Redis command operations, I suggest you bookmark the Redis Command Reference website in your browser and look it up as needed. Currently, the command reference provided by the Redis official website is definitely the most complete and up-to-date. I recommend using this official website as a priority. It is very convenient to search for command operations on this webpage. We can search directly by the name of the command operation or find the operations under corresponding functionalities, such as cluster-related operations or publish-subscribe-related operations. Considering that some students may prefer the Chinese version, I will also provide a translated version of the command reference.

In addition to providing an introduction to Redis command operations, the “Redis Usage Manual” also includes the “Additional Functions” section, which introduces management operations of Redis databases and operations related to expiring keys. This provides guidance for performing Redis database operations (such as data migration, database clearance, data elimination, etc.).

With the tool manual, we can easily grasp the input parameters, return results, and complexity of different command operations. Next, we can further understand the principles behind various mechanisms. Let me share a book on principles with you.

Principles: “Redis Design and Implementation” #

Although “Redis Design and Implementation” and “Redis Usage Manual” are written by the same author, they have different focuses. This book focuses more on the implementation principles of key mechanisms in Redis. There are many resources that explain the principles of Redis, but I think this book explains them very thoroughly, especially in terms of the underlying data structures, RDB and AOF persistence mechanisms, as well as the Sentinel mechanism and sharded clusters. It is very easy to understand, so I suggest you focus on studying these parts.

In addition to the written explanation, this book uses clear illustrations to represent some difficult problems, such as the composition of data structures, the interaction process between Sentinel instances, and the interaction process between sharded cluster instances. This greatly reduces the learning difficulty.

In fact, this book was the first Redis reference book I read myself. It can be said that it led me into the world of Redis principles. When I was learning, it was these illustrations that helped me quickly understand the core principles. Even today, I still remember some of the illustrations in this book. I have benefited a lot from it.

Although this book was published earlier (it is targeted at Redis 3.0), many of the principles discussed are still applicable. It can help you take a big step forward on the journey from getting started with Redis to becoming proficient.

Practical Book: “Redis in Action” #

For practical purposes, “Redis in Action” is a good reference book.

Firstly, it introduces Redis Java and Python clients, as well as key technologies and considerations for Redis cache design. These contents are not very common in other reference books, so you can focus on studying them.

Secondly, it focuses on several aspects such as clients, persistence, master-slave replication, Sentinel, sharded clusters, and introduces the problems and “pitfalls” encountered in the daily development and operation process. These are all based on experience and can help you avoid problems in advance.

In addition, this book provides solutions to classic problems such as Redis blocking, optimizing memory usage, and dealing with bigkeys. It is worth reading. When reading, you can organize the problems in the table of contents into a list. This way, when you encounter a problem, you can quickly identify the cause and solve it using the solutions in the book.

Of course, reading alone is far from enough to truly improve your practical skills, after all, “paper can only take you so far”. So, I would like to share two more suggestions with you.

The first suggestion is to read the source code. Reading the source code is actually a kind of practical exercise, which can help you thoroughly understand the actual operating mechanism of the Redis system from the code logic. When encountering problems, you can directly locate, analyze, and solve them from the code level. The most direct material for reading the Redis source code is the source code repository on GitHub. In addition, there is a website that provides partial Chinese annotations for Redis 3.0 source code, and you can also refer to it.

In addition, we also need to practice hands-on. I saw some students saying in the course comments, “without a server, it is impossible to practice,” but in fact, once Redis is running, it is already a process. We can directly deploy it on our own computers. As long as it is not performance testing, our own computer environment is generally sufficient for functional testing or scenario simulation. For example, to deploy a master-slave cluster or sharded cluster and simulate a failure of the master database, we can completely set up multiple Redis instances on our own computers, as long as they have different port numbers.

Alright, that’s it for the recommended books about Redis itself. Next, I would like to share some additional content with you.

Through the previous few lessons, I believe you must have discovered that many key features of Redis are actually related to the underlying implementation mechanisms of the operating system, such as non-blocking network frameworks, the fork and copy-on-write mechanisms involved in RDB generation and AOF rewriting, and so on. In addition, the sentinel mechanism in Redis master-slave clusters and the data distribution in sharded clusters also involve some content related to distributed systems.

I used an image to demonstrate the key mechanisms of Redis and their corresponding knowledge points in operating systems and distributed systems.

The flush timing of AOF logs is related to the fsync mechanism of the operating system and the flush-back of the high-speed page cache, while the network framework is related to epoll. RDB generation and AOF rewriting are related to fork and copy-on-write (as I mentioned in lectures 3, 4, and 5).

In addition, the leader selection process of sentinels I introduced in [Lesson 8] is actually the execution process of the classic Raft protocol in distributed systems. If you are familiar with the Raft protocol, you can easily grasp the running mechanism of sentinel leader selection. In [Lesson 9], we learned about the Redis Cluster solution for sharded clusters. In fact, there is another implementation solution in the industry called ShardedJedis, which uses the classic consistent hashing mechanism in distributed systems.

Therefore, if you want to enhance your practical abilities, I recommend you read some classic textbooks on operating systems and distributed systems, such as “Introduction to Operating Systems”. Especially the definition of processes and threads, the introduction of process APIs, thread APIs, fsync operations on file systems, caching, and buffering are directly relevant to Redis. For example, the distributed systems section of “Principles and Practice of Large-Scale Distributed Storage Systems” can help you master the design specifications involved in Redis master-slave clusters and sharded clusters. Understanding the basics of operating systems and distributed systems can not only help you clarify easily confused concepts (such as Redis main threads and child processes) but also enable you to apply some common design methods (such as consistent hashing) to daily practice, achieve integration of knowledge, and extrapolate from one example to another.

Summary #

In this lesson, I recommended three reference books for you, each corresponding to the command operation, the implementation principles of key mechanisms, and practical experience of Redis. I also introduced two websites for quick reference of Redis command operations. These are essential tools for our daily use of Redis and can help improve your efficiency in using and operating Redis. Additionally, I supplemented the key mechanisms of Redis with knowledge from the perspectives of operating systems and distributed systems.

Reading the Redis source code is a necessary step to become an expert in Redis. You can read the Redis source code repository on GitHub. If you find it difficult, you can also start with websites that provide annotated source code in Chinese.

Lastly, I would like to chat with you about the learning materials you have for Redis. Please feel free to share in the comments section so we can progress together. Also, if you found today’s content helpful, please feel free to share it with your friends or colleagues.