Redis Master Slave with Docker

Redis Master Slave with Docker

etting Up Redis Master-Slave Replication with Docker on macOS

In this tutorial, we’ll set up a simple Redis Master-Slave Replication architecture using Docker on macOS. This setup includes one master and two slave nodes to achieve high availability and read scalability.

Why Use Redis Replication?

Redis is a blazing fast in-memory key-value store, but by default, it runs as a standalone instance. Replication helps to:

• Distribute read load

• Improve data availability

• Enable backup and failover scenarios

Step 1: Create a Docker Network

We’ll start by creating an isolated Docker network so containers can communicate with each other:

docker network create redis-net

 Step 2: Run the Redis Master Container

docker run -d --name redis-master --network redis-net redis

Step 3: Run Redis Slave Containers

Slave 1:

docker run -d --name redis-slave-1 --network redis-net redis redis-server --replicaof redis-master 6379

Slave 2:

docker run -d --name redis-slave-2 --network redis-net redis redis-server --replicaof redis-master 6379

Step 4: Verify Docker Containers

docker ps

CONTAINER ID   IMAGE   ...   NAMES
...            redis   ...   redis-slave-2
...            redis   ...   redis-slave-1
...            redis   ...   redis-master

Step 5: Test Replication

docker exec -it redis-master redis-cli set name ibrahim

Read from a slave:

docker exec -it redis-slave-1 redis-cli get name

 Step 6: Check Replication Status

docker exec -it redis-master redis-cli info replication

role:master
connected_slaves:2
slave0:ip=...,state=online
slave1:ip=...,state=online

On a slave:

docker exec -it redis-slave-1 redis-cli info replication

role:slave
master_host:redis-master
master_link_status:up

Bir yanıt yazın

E-posta adresiniz yayınlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir

Back To Top