Redis Cluster
Hash slots, resharding, and the multi-key constraints that shape application code in a clustered Redis.
Redis Cluster distributes the keyspace across primaries using 16384 hash slots, with automatic failover and no separate coordinator process.
Slots and key routing
The slot for a key is CRC16(key) mod 16384. Each primary owns a contiguous set of slots. Clients
cache the slot map and connect directly to the owning node; if a slot has moved, the node replies
MOVED and the client updates its map.
redis-cli --cluster create \
10.20.1.10:6379 10.20.1.11:6379 10.20.1.12:6379 \
10.20.1.20:6379 10.20.1.21:6379 10.20.1.22:6379 \
--cluster-replicas 1CLUSTER INFO
CLUSTER SHARDS
CLUSTER KEYSLOT shop:user:1001Multi-key operations
Failover
Each primary should have at least one replica. Nodes gossip; when a majority of primaries agree a node is failing, one of its replicas is promoted.
The cluster requires a majority of primaries to be reachable to remain available. With
cluster-require-full-coverage yes (the default), the cluster stops serving all requests if any
slot is uncovered. Setting it to no keeps the healthy slots serving while the affected range
errors — usually the better behaviour for a cache.
Resharding
# Move 1000 slots to a new node.
redis-cli --cluster reshard 10.20.1.10:6379 \
--cluster-from <source-node-id> \
--cluster-to <target-node-id> \
--cluster-slots 1000 --cluster-yes
# Even out slot distribution after adding nodes.
redis-cli --cluster rebalance 10.20.1.10:6379Constraints to design around
- One database only.
SELECTis not supported in cluster mode; there is only database 0. - No cross-slot transactions or scripts.
SCANis per node, so a full keyspace scan means iterating every primary.- Pub/Sub is broadcast cluster-wide unless you use sharded pub/sub (
SPUBLISH). - Client libraries must be cluster-aware. A plain client will follow
MOVEDredirects poorly or not at all.
When you do not need it
Cluster exists to exceed one node's memory or throughput. If the dataset fits comfortably in one instance's RAM and one core can serve the command rate, a primary with replicas and Sentinel is simpler to operate and imposes none of the multi-key constraints above.