I have been busy these days, and the sentinel/cluster/copy code is also quite large, so it took some time to sort it out. It’s probably going to take about 10 chapters to break it all down. I’m not going to do it because I don’t have enough time. Here directly put the code, there are detailed comments, may understand some deviation, but I feel that the basic understanding of 90%. The replica is simply responsible for synchronizing data between the slave and master, while the sentinel monitors the specified master/slave node. Checks whether the master node is offline, automatically performs failover, and elects a new master node. The core logic is that sentinels synchronize information with each other, connect with other masters/slaves, and send heartbeat check. When the master is found offline, a failover handler is determined in the sentinels cluster (a leader is determined in multiple sentinels, and only one leader exists in one epoch). And notify slaves of promotions and master changes of other slaves. Sentries sense each other through pubsub. (When the sentinels observe the same slave/master, the slave/master will publish the Hello information sent by the sentinels to all the sentinels subscribed to realize dynamic discovery.) In addition, the client can receive the events sent by the sentinels through subscription (such as discovering a new slave, Master offline, slave promoted, etc.), which is also an extension of Redis.

The code entry is usually in xxxCron, also with redis. ServerCron as the entry.

The rest of the Redis modules are corners, the difficulty is relatively low, I will not talk about.

Github.com/a137872798/… Github.com/a137872798/… Github.com/a137872798/…