Databases 10 min read

Understanding Redis Master‑Slave Replication and Its Configuration

This article explains how Redis master‑slave replication works, covering asynchronous copying, partial resynchronization, disk‑less replication, safety considerations when persistence is disabled, read‑only slaves, authentication, and configuration options such as slaveof and write‑restriction based on slave count.

Architect
Architect
Architect
Understanding Redis Master‑Slave Replication and Its Configuration

Key Points of Redis Master‑Slave Replication

Redis replication is simple to configure and creates an exact copy of the master on one or more slaves. It operates asynchronously, allows multiple slaves per master, and even permits slaves to have their own slaves, forming a graph topology.

Safety When the Master Does Not Persist Data

Disabling persistence on the master while allowing automatic restarts is dangerous because a crash can leave the master with an empty dataset, causing all slaves to lose data during subsequent synchronizations.

How Replication Works

When a slave connects, it sends a SYNC command. The master starts a background save, buffers incoming write commands, and after the RDB file is ready, sends it to the slave, which loads it into memory. The buffered commands are then streamed to the slave.

Partial Resynchronization (PSYNC)

From Redis 2.8 onward, if a connection drops, the slave can reconnect and continue replication from the last offset stored in the master’s in‑memory backlog, provided the master run‑id matches and the offset is still available; otherwise a full resynchronization occurs.

Disk‑less Replication

Since Redis 2.8.18, the master can stream the RDB file directly over the network without writing it to disk, using the repl-diskless-sync option and optionally delaying the start with repl-diskless-sync-delay.

Configuration

To enable replication, add the following line to the slave’s configuration file: slaveof 192.168.1.1 6379 Replace the IP and port with those of your master. You can also issue the SLAVEOF command at runtime.

Read‑Only Slaves

Starting with Redis 2.6, slaves are read‑only by default (controlled by the slave-read-only setting). Write commands are rejected, though administrative commands like DEBUG or CONFIG can still be executed unless renamed.

Master Authentication for Slaves

If the master requires a password, configure the slave with: config set masterauth <password> To make it permanent, add masterauth <password> to the configuration file.

Write Restriction Based on Number of Slaves

From Redis 2.8, the master can be set to accept writes only when at least N slaves have confirmed replication within M seconds, using the min-slaves-to-write and min-slaves-max-lag settings. This provides a best‑effort consistency guarantee.

For detailed parameter descriptions, refer to the Redis.conf example in the Redis documentation.

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
Architect
Written by

Architect

Professional architect sharing high‑quality architecture insights. Topics include high‑availability, high‑performance, high‑stability architectures, big data, machine learning, Java, system and distributed architecture, AI, and practical large‑scale architecture case studies. Open to ideas‑driven architects who enjoy sharing and learning.

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.