slots understanding

Redis Cluster Slot Assignment

Understanding Slot Assignment in Redis Cluster

If Node 2 has a replica, and you want to know where the key slots go for the primary node (master), here's how it works:

How Redis Cluster Handles Slots


In a Redis Cluster:

  • Each primary node (master) is responsible for a range of slots.
  • Replica nodes (slaves) are used for redundancy and failover purposes. They do not directly handle slot assignments themselves but replicate the data from their associated master node.

Scenario

Let’s assume the following:

  • Node 2 is a replica of a primary node (Master).
  • The primary node (Master) owns a certain range of slots.
  • The replica node (Node 2) simply mirrors the data of the primary node.

In this case, the slots are not directly assigned to the replica. Instead, the replica backs up the data from the primary node and handles failover if the primary node goes down.

Key Points

  • Slot Ownership: The primary node owns the slots, not the replica. If Node 2 is a replica, it replicates the data and keys from the primary node but does not own or manage any hash slots.
  • Failover Handling: If the primary node fails, the replica (Node 2) will be promoted to the new primary for the same slots it was previously replicating.

Example

Assume a cluster has 3 nodes:

  • Node 1 (Primary): Responsible for slots 0 to 5460
  • Node 2 (Replica): Replicates Node 1’s slots
  • Node 3 (Primary): Responsible for slots 5461 to 10922

If Node 1 (primary) fails:

  • The Redis Cluster will promote Node 2 to take over the primary role for slots 0 to 5460.
  • The other replica of Node 3 (if it exists) will handle the slots 5461 to 10922.

Summary

Primary Node (Master): Owns the slots and directly handles the data for those slots.
Replica Node: Replicates the data of its associated master but does not own the slots.
Failover: If the primary node fails, the replica node is promoted to the primary and takes over the slots it was replicating.

This structure ensures high availability in Redis Cluster, where each master node's data is replicated to its associated replica. In case of failure, the cluster automatically promotes a replica to maintain service continuity.

Comments