Understanding Redis Deployment Modes: Standalone, Master‑Slave, Sentinel, and Cluster
This article provides a comprehensive guide to Redis deployment, covering standalone, master‑slave replication, Sentinel high‑availability, and cluster sharding modes, detailing their principles, advantages, drawbacks, and step‑by‑step configuration examples with Maven dependencies and Redis configuration files.
Overview
Redis is a high‑performance caching middleware that is widely used in development. It offers four deployment modes: standalone , master‑slave replication , Sentinel , and cluster .
Standalone Mode
Advantages
Simple implementation, low maintenance cost, easy deployment, and no additional expenses.
Disadvantages
Single‑point‑of‑failure, limited concurrency and storage capacity, and slow restart when the dataset is large.
Setup
In a Spring Boot project, add the Jedis dependency:
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>${jedis.version}</version>
</dependency>Common redis.conf options (excerpt):
daemonize yes # run in background
pidfile /var/run/redis.pid # pid file
port 6379 # default port
bind 127.0.0.1 # allow only local connections (use 0.0.0.0 for any)
maxmemory 3gb # memory limit
maxmemory-policy volatile-lru # eviction policy
appendonly no # AOF disabled
appendfsync everysec # AOF fsync strategy
# ... (other settings omitted for brevity)Master‑Slave Mode
Principle
One master handles reads and writes; one or more slaves replicate the master and serve read‑only traffic, achieving read‑write separation.
Advantages
Reduces read pressure on the master, improves availability by providing a standby when the master fails, and forms the basis for Sentinel and cluster setups.
Disadvantages
Potential data inconsistency during replication lag, manual failover, and limited write scalability.
Setup
Configure the master (e.g., redis-6379.conf) and slaves (e.g., redis-6380.conf, redis-6381.conf) with:
# Master configuration (redis-6379.conf)
bind 0.0.0.0
protected-mode no
port 6379
daemonize yes
requirepass 123456
# ... other settings
# Slave configuration (redis-6380.conf)
slaveof 127.0.0.1 6379
masterauth 123456
slave-serve-stale-data noStart each instance:
./redis-server /root/redis/6379.conf
./redis-server /root/redis/6380.conf
./redis-server /root/redis/6381.confSentinel Mode
Principle
Sentinel monitors master and slaves, detects failures, and automatically promotes a slave to master, eliminating manual intervention.
Key Commands
SENTINEL MONITOR <master-name> <ip> <port> <quorum>– registers the master to be monitored. SENTINEL AUTH-PASS <master-name> <password> – sets the master password.
SENTINEL DOWN‑AFTER‑MILLISECONDS <master-name> <ms>– failure detection timeout. SENTINEL FAILOVER‑TIMEOUT <master-name> <ms> – failover timeout.
Setup
Create three sentinel configuration files (e.g., sentinel1.conf, sentinel2.conf, sentinel3.conf) with:
daemonize yes
port 26379
sentinel monitor mymaster 127.0.0.1 6379 1
sentinel auth-pass mymaster 123456
sentinel down-after-milliseconds mymaster 3000
sentinel parallel-syncs mymaster 2
sentinel failover-timeout mymaster 100000Start the sentinels:
./redis-server sentinel1.conf --sentinel
./redis-server sentinel2.conf --sentinel
./redis-server sentinel3.conf --sentinelCluster Mode
Principle
Redis Cluster shards data across multiple nodes using 16,384 hash slots. Each key is mapped to a slot (CRC16(key) % 16384) and stored on the node responsible for that slot.
Advantages
Horizontal scalability, high availability, and distributed storage without a single point of failure.
Disadvantages
Increased architectural complexity, minimum of six nodes for a production cluster, and eventual consistency rather than strong consistency.
Setup
Enable cluster in each redis.conf:
port 6379
daemonize yes
cluster-enabled yes
cluster-config-file nodes_6379.conf
cluster-node-timeout 10000
masterauth 123456Start six instances (ports 6379‑6384) and create the cluster:
./redis-cli --cluster create --cluster-replicas 1 \
127.0.0.1:6379 127.0.0.1:6380 127.0.0.1:6381 \
127.0.0.1:6382 127.0.0.1:6383 127.0.0.1:6384 -a 123456After creation, the cluster distributes slots among the masters and sets up replicas.
Conclusion
The article walks through the four Redis deployment models, explains their inner workings, lists pros and cons, and provides concrete configuration and deployment commands, enabling readers to choose and implement the appropriate mode for their use case.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
