Skip to main content

Managing Redis Cluster

1. Understanding Cluster Architecture

ConceptDetail
Slots16384 hash slots distributed across masters
ShardingCRC16(key) mod 16384
High availabilityEach master can have replicas
No DB selectOnly DB 0 supported

2. Creating Cluster Nodes

cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 15000
cluster-require-full-coverage no

3. Joining Cluster

CommandDescription
redis-cli --cluster create h1:p h2:p ... --cluster-replicas 1Bootstrap cluster
CLUSTER MEET ip portAdd node to existing cluster

4. Adding Slots to Nodes

CommandDescription
CLUSTER ADDSLOTS slot [slot ...]Assign individual slots
CLUSTER ADDSLOTSRANGE s e [s e]Range form 7.0+
CLUSTER DELSLOTS / DELSLOTSRANGEUnassign

5. Migrating Slots

ToolDescription
redis-cli --cluster reshardInteractive slot migration
CLUSTER SETSLOT slot MIGRATING|IMPORTING|STABLE|NODELow-level state

6. Getting Cluster Info

CommandReturns
CLUSTER INFOstate, slots_assigned, known_nodes
CLUSTER SHARDSShard-level layout 7.0+
CLUSTER COUNTKEYSINSLOT slotPer-slot key count

7. Listing Cluster Nodes

CommandDescription
CLUSTER NODESFull node table (id, addr, flags, slots)
CLUSTER MYIDLocal node id

8. Understanding Hash Slot Distribution

Example: Hashtag pins keys to one slot

SET {user:42}:profile "..."
SET {user:42}:cart    "..."
# Both keys map to the same slot via "user:42"
UseDetail
Multi-key opsRequire same slot — use {tag}

9. Configuring Cluster Replicas

CommandDescription
CLUSTER REPLICATE master-idAttach replica to master
cluster-replica-validity-factorDisqualify stale replicas for failover

10. Handling Cluster Failover

CommandUse
CLUSTER FAILOVERReplica takes over its master
CLUSTER FAILOVER FORCESkip handshake
CLUSTER FAILOVER TAKEOVERBypass majority — use only in disaster

11. Resharding Cluster

CommandDescription
redis-cli --cluster reshard host:portInteractive resharding
redis-cli --cluster rebalanceEven slot distribution

12. Monitoring Cluster Health

CommandDescription
redis-cli --cluster check host:portTopology + slot coverage check
CLUSTER LINKSPer-link diagnostic 7.0+

13. Using Cluster-Aware Clients

CapabilityDetail
MOVED redirectionClient caches slot→node mapping
ASK redirectionSingle-command redirect during migration
READONLYIssue on replica connection for replica reads

14. Handling Network Partitions

RiskMitigation
Split-brain writesSet cluster-require-full-coverage yes to stop writes when slots missing
Minority partitionRefuses writes if it can't reach majority

Was this article helpful?