All About Redis Cluster: Architecture, Setup, Operations, and High‑Availability
This article provides a comprehensive guide to Redis Cluster, covering its background, overall architecture, deployment steps, configuration templates, cluster creation commands, basic key‑value operations, high‑availability testing, and how to manually assign master‑slave relationships for robust distributed caching.
Redis Cluster is introduced as a solution to the scalability and high‑availability limitations of single‑node Redis and its master‑replica mode.
1. Background
Rapid growth of internet services and data volumes require a distributed, fault‑tolerant in‑memory store; Redis Sentinel adds failover but lacks sharding, prompting the need for Redis Cluster.
2. Overall Introduction
Redis Cluster partitions data into 16,384 hash slots, distributing them across multiple nodes. Each node handles a subset of slots, enabling horizontal scaling and automatic health checks.
3. Application Scenarios
High‑concurrency read/write (e‑commerce flash sales, social media spikes, game leaderboards)
Large‑scale data storage (user profiles, IoT sensor streams, log/event buffers)
High availability and disaster recovery (financial transaction caching, multi‑region deployments, session storage)
Dynamic scaling (rapid traffic growth, promotional bursts, cloud‑native auto‑scaling)
4. Environment Setup
Create a working directory and separate sub‑folders for each port (7000‑7005). Use the following configuration template (adjust the port number for each instance):
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"Copy the template to each folder, modify the port and file names, then start the six instances:
./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 &5. Creating the Cluster
Use redis-cli --cluster create with all node addresses and specify one replica per master:
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 123456The command distributes slots (0‑5460, 5461‑10922, 10923‑16383) among three masters and creates a slave for each.
6. Basic Operations
Connect with redis-cli -c -a 123456 -h 127.0.0.1 -p 7000 and perform normal SET / GET commands. The client automatically redirects keys to the node owning the corresponding slot.
7. High‑Availability Test
Shut down a master (e.g., port 7000). The former slave (port 7004) is promoted to master, and the original master becomes a slave when it restarts. If both master and its slave are stopped, the cluster reports cluster_state:fail and becomes unavailable.
8. Specifying Master‑Slave Relationships
First create a three‑node cluster without replicas, then add a node as a slave of a chosen master:
redis-cli --cluster add-node -a 123456 127.0.0.1:7003 127.0.0.1:7001 --cluster-slave --cluster-master-idAfter the command, cluster nodes shows the new slave relationship.
9. Other Notes
The article mentions additional topics such as slot rebalancing (resharding), split‑brain handling, and inter‑node communication, which are beyond the current scope.
For further reading, see the recommended articles on Bloom filters, common interview questions, and distributed locks in Redis.
Full-Stack Internet Architecture
Introducing full-stack Internet architecture technologies centered on Java
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.