Databases 11 min read

Redis Cluster: Architecture, Setup, Testing, and High Availability

This article explains Redis Cluster's sharding architecture, demonstrates how to configure multiple Redis nodes on different ports, shows commands for creating and testing the cluster, and illustrates failover behavior, highlighting its scalability and high‑availability advantages over Sentinel mode for large‑scale data workloads.

Full-Stack Internet Architecture
Full-Stack Internet Architecture
Full-Stack Internet Architecture
Redis Cluster: Architecture, Setup, Testing, and High Availability

Redis provides a high‑availability solution called Sentinel, but its single‑master design limits storage capacity and performance for large‑scale data; Redis Cluster addresses this by sharding data across multiple nodes, greatly increasing capacity and horizontal scalability.

The cluster consists of 16384 hash slots; each key is hashed (CRC16) and assigned to a slot, which determines the node responsible for that key. Nodes manage specific slot ranges, enabling efficient data distribution.

To set up a Redis Cluster on a single server, create separate directories for each port (7000‑7005) and copy a base redis.conf into each, modifying parameters such as port , cluster-enabled yes , cluster-config-file , cluster-node-timeout , and authentication settings.

port 7000
cluster-enabled yes
cluster-config-file nodes-7000.conf
cluster-node-timeout 5000
dbfilename "dump-7000.rdb"
protected-mode no
logfile "logfile-7000.log"
requirepass 123456
masterauth 123456
pidfile "redis_7000.pid"

Create the directory structure and start each instance:

mkdir cluster-test
cd cluster-test
mkdir 7000 7001 7002 7003 7004 7005
./redis-server ./cluster-test/7000/redis.conf &
./redis-server ./cluster-test/7001/redis.conf &
./redis-server ./cluster-test/7002/redis.conf &
./redis-server ./cluster-test/7003/redis.conf &
./redis-server ./cluster-test/7004/redis.conf &
./redis-server ./cluster-test/7005/redis.conf &

After the nodes are running, create the cluster with:

redis-cli --cluster create 127.0.0.1:7000 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 --cluster-replicas 1 -a 123456

The command distributes the 16384 slots among the three master nodes (each with a replica), and the output confirms slot allocation and node roles.

Testing the cluster with redis-cli -h 127.0.0.1 -p 7000 -c -a 123456 shows automatic redirection based on slot calculation:

127.0.0.1:7000> set slogan good
-> Redirected to slot [16191] located at 127.0.0.1:7002
OK
127.0.0.1:7000> get slogan
-> Redirected to slot [16191] located at 127.0.0.1:7002
"good"

Failover is demonstrated by stopping a master (e.g., port 7002); the corresponding slave (port 7003) is promoted to master, and the original master becomes a slave when it rejoins.

Cluster health can be inspected with redis-cli --cluster check 127.0.0.1:7000 -a 123456 , which reports slot coverage, master/slave roles, and key distribution.

Overall, Redis Cluster provides strong scalability and high availability through data sharding and automatic failover, making it a more advanced solution than Sentinel for demanding workloads.

databaseShardingHigh AvailabilityRedisClusterscaling
Full-Stack Internet Architecture
Written by

Full-Stack Internet Architecture

Introducing full-stack Internet architecture technologies centered on Java

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.