Redis cluster failover method: 1. Elect a new master from all slave nodes; 2. The elected new master will execute slaveof no one to change its status from slave to master; 3. Cancel the slot assignments of the offline master node and reassign these slots to yourself.
Redis cluster failover method:
1. Fault detection
- 1. All nodes in the cluster will send PING messages to other nodes. If no corresponding PONG message is received within the specified time, the node will be marked as suspected to be offline;
- 2. In The PING message sent will carry the current cluster and node information; in this way, the survival of the node can be detected and the unity of the cluster information can be maintained, but there is a certain
delay;
- 3. Suspected offline is not really offline. Only when the following conditions are met can it be truly offline;
- The master node is the master node assigned a slot. Only when more than half of the nodes think that the node is suspected to be offline can it really go offline;
- 4. When a node learns through a message that a node's suspected offline votes have exceeded half of the cluster's votes , will send a broadcast message indicating that this node is offline;
- 5. After other nodes receive the broadcast that a node is offline, they will also modify their own internal cluster maintenance information to the node offline status. .
2. Failover
- 1. Elect a new master from all slave nodes;
- 2. The elected new master will Execute slaveof no one to change your status from slave to master;
- 3. Revoke the slot assignments of the offline master node and reassign these slots to yourself;
- 4. The new master node broadcasts a PONG message to the cluster, telling all cluster nodes through this message that it has become the master node and has taken over the original master node;
- 5. New master node Start receiving and processing command requests related to its own slot.
Related learning recommendations:redis video tutorial
The above is the detailed content of How to implement Redis cluster failover. For more information, please follow other related articles on the PHP Chinese website!