Databases 5 min read

How to Set Up Redis Master‑Slave Replication in Minutes

This guide walks you through configuring a simple Redis master‑slave setup, covering the benefits, step‑by‑step file modifications, essential replication directives, testing procedures, and common pitfalls to ensure high availability and read/write separation.

360 Zhihui Cloud Developer
360 Zhihui Cloud Developer
360 Zhihui Cloud Developer
How to Set Up Redis Master‑Slave Replication in Minutes

Introduction

Redis master‑slave replication is the foundation of many high‑availability architectures such as read/write separation, primary‑secondary, and multi‑level replication. This article briefly introduces how to configure a simple one‑master‑one‑slave setup.

Advantages

Eliminates single‑point failure; if the master crashes, the slave can take over.

Enables read/write separation under a master‑slave topology.

Steps

Copy the default redis.conf to two separate files, e.g., redis.6379.conf and redis.6380.conf .

Edit each file according to its role (master or slave).

Master Configuration

port 6379 /usr/local/var/run/redis.6379.pid appendfilename "appendonly.6379.aof" dbfilename dump.6379.rdb requirepass 123456

Slave Configuration

port 6380 /usr/local/var/run/redis.6380.pid appendfilename "appendonly.6380.aof" dbfilename dump.6380.rdb requirepass 123456

Replication Settings

slaveof 127.0.0.1 6379 masterauth 123456

Start and Test

Launch both instances:

redis-server redis.6379.conf redis-server redis.6380.conf

Connect with redis-cli on each port, authenticate, and verify that keys set on the master are visible on the slave.

Possible Errors

On some Vagrant boxes the slave may report connected_slaves:0 . Ensure the slaveof line uses the correct IP (127.0.0.1) and that /etc/hosts does not map localhost to both IPv4 and IPv6 addresses. Commenting out the IPv6 entry or binding only to 127.0.0.1 resolves the issue.

Conclusion

Configuring Redis master‑slave replication is straightforward and requires only a few key directives. Understanding this basic setup paves the way for more complex topologies such as one‑master‑multiple‑slaves or multi‑level replication.

DatabaseHigh AvailabilityRedisConfigurationMaster-Slave Replication
360 Zhihui Cloud Developer
Written by

360 Zhihui Cloud Developer

360 Zhihui Cloud is an enterprise open service platform that aims to "aggregate data value and empower an intelligent future," leveraging 360's extensive product and technology resources to deliver platform services to customers.

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.