Redis Cluster for Horizontal Scaling
Advanced20 min
Deploy a Redis Cluster with automatic data sharding and high availability across multiple nodes for production workloads.
Prerequisites
- -Redis 7+ installed
- -At least 6 Redis instances (3 masters, 3 replicas)
- -Network connectivity between all nodes
Steps
1
Prepare cluster configuration
Enable cluster mode in each Redis instance configuration.
$ redis-cli -p 7001 CONFIG SET cluster-enabled yes && redis-cli -p 7001 CONFIG SET cluster-config-file nodes-7001.conf && redis-cli -p 7001 CONFIG SET cluster-node-timeout 5000
Repeat for ports 7002-7006. Each node needs a unique cluster-config-file.
2
Create the cluster
Initialize the cluster with 3 masters and 3 replicas using redis-cli.
$ redis-cli --cluster create 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 127.0.0.1:7006 --cluster-replicas 1
This redistributes all hash slots. Run on a fresh cluster or expect data to be reshuffled.
3
Verify cluster status
Check that all nodes joined the cluster and slots are assigned.
$ redis-cli -p 7001 CLUSTER INFO
4
Check cluster node roles
List all nodes with their roles, slot ranges, and replication status.
$ redis-cli -p 7001 CLUSTER NODES
5
Test cluster operations
Write and read data using cluster-aware mode in redis-cli.
$ redis-cli -c -p 7001 SET mykey 'hello' && redis-cli -c -p 7001 GET mykey
The -c flag enables cluster mode in redis-cli, automatically following MOVED redirections.
Full Script
FAQ
Discussion
Loading comments...