Introducing Dragonfly Cloud! Learn More

Question: What is the difference between Redis master-replica setup and clustering?

Answer

Redis provides two different mechanisms for handling distributed storage: Master-Replica setup and Clustering.

A Master-Replica setup involves a single "master" Redis instance and one or more "replica" instances. The replicas mirror the data of the master. The purpose of this setup is mostly to scale reads and provide redundancy. If the master goes down, one of the replicas can be promoted to master.

Here's how you can set it up:

redis-server --port 6379 redis-server --port 6380 --slaveof 127.0.0.1 6379

The first command starts a Redis server acting as the master on port 6379 and the second command starts another Redis server acting as a replica to the master, running on port 6380.

On the other hand, Redis Cluster is a distributed implementation of Redis with two main goals: providing a degree of write scalability and providing high availability. Write commands are divided among multiple nodes so that each node only holds a subset of the total dataset. Additionally, the cluster maintains a certain number of replicas for redundancy and failover purposes.

Setting up a cluster involves several steps but here's a simple example using the create-cluster script provided by Redis:

cd src ./redis-cli --cluster create 127.0.0.1:7000 127.0.0.1:7001 \ 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 \ --cluster-replicas 1

This command sets up a six-node Redis Cluster, with three master nodes and three corresponding replica nodes.

The choice between Master-Replica setup and Clustering depends on the use case. Master-Replica setups are simpler to manage and are ideal when read scalability or data redundancy is required, whereas Redis Clusters provide more write scalability and higher availability through automatic partitioning of data.

Was this content helpful?

White Paper

Free System Design on AWS E-Book

Download this early release of O'Reilly's latest cloud infrastructure e-book: System Design on AWS.

Free System Design on AWS E-Book

Start building today 

Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement.