Databases 7 min read

Redis Master‑Slave Replication: Configuration and Operation Guide

This article explains Redis master‑slave replication, detailing the replication principles, full‑sync steps, essential configuration file settings, commands to establish replication, verification methods, and a practical test showing data synchronization between master and slave instances.

Practical DevOps Architecture
Practical DevOps Architecture
Practical DevOps Architecture
Redis Master‑Slave Replication: Configuration and Operation Guide

Redis supports master‑slave replication, allowing data to be synchronized from a master server to any number of slave servers, which can themselves act as masters for further slaves, forming a single‑level tree replication that enhances read scalability and data redundancy.

The replication architecture can be a one‑master‑multiple‑slaves or a cascaded structure, and synchronization occurs either as a full sync (initial copy) or an incremental sync (subsequent changes).

Full synchronization proceeds through the following steps:

1) The slave connects to the master and sends the SYNC command. 2) The master receives SYNC, runs BGSAVE to generate an RDB snapshot while buffering subsequent write commands. 3) After BGSAVE completes, the master streams the snapshot to all slaves, continuing to record writes. 4) The slave discards old data, loads the received snapshot. 5) Once the snapshot transfer finishes, the master streams buffered write commands to the slaves. 6) The slave, after loading the snapshot, starts applying the buffered write commands.

Key configuration parameters in /etc/redis/redis.conf include:

daemonize yes
pidfile "/var/run/redis6379.pid"
port 6379
timeout 0
loglevel notice
logfile "stdout"
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename "dump.rdb"
dir "/data/redis_db/6378"
protected-mode no
replica-serve-stale-data yes
replica-read-only yes
requirepass 123456
maxmemory 20gb
appendonly no
appendfsync everysec
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
lua-time-limit 5000
slowlog-log-slower-than 10000
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
maxclients 50000

To configure replication, execute on the slave:

127.0.0.1:6379> SLAVEOF 192.168.20.8 6378
127.0.0.1:6379> CONFIG set masterauth 123456

Verify synchronization on the slave with: 127.0.0.1:6379> INFO Replication The output shows role:slave, master host/port, link status, and replication offsets, confirming the connection.

On the master, test data replication by setting keys:

127.0.0.1:6378> set name age
127.0.0.1:6378> set k1 v1

Reading the keys on the slave returns the same values, demonstrating successful replication: 127.0.0.1:6379> get name

"age"
127.0.0.1:6379> get k1

"v1" This guide provides a complete walkthrough for setting up, configuring, and testing Redis master‑slave replication.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

DatabaseRedisconfigurationreplicationMaster‑Slave
Practical DevOps Architecture
Written by

Practical DevOps Architecture

Hands‑on DevOps operations using Docker, K8s, Jenkins, and Ansible—empowering ops professionals to grow together through sharing, discussion, knowledge consolidation, and continuous improvement.

0 followers
Reader feedback

How this landed with the community

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.