Dragonfly Cloud is now available on the AWS Marketplace - Learn More

Question: How can I set up Redis replication?

Answer

In Redis, replication is a functionality that allows data from one Redis server to be mirrored on any number of replicas. A master server is responsible for performing all writes and reads, while the replicas are used to replicate the master's dataset.

Here is the step-by-step guide to set up replication:

Step 1: Install Redis on both the master and replica servers.

You can install Redis using package managers like apt for Ubuntu:

sudo apt update sudo apt install redis-server

Step 2: Configure the replica to know who the master is.

To configure a Redis server as a replica, you need to include one simple directive in your redis.conf file:

replicaof <masterip> <masterport>

For example,

replicaof 127.0.0.1 6379

This tells the system that this Redis instance is a replica and it should replicate data from the master located at IP address 127.0.0.1 and port 6379.

After making changes to the configuration file, restart the Redis service:

sudo systemctl restart redis.service

Step 3: Verify the replication setup

You can check the details of the replication using the following command in the Redis CLI:

INFO REPLICATION

The output will show if the Redis instance is a master or a replica and other details about the replication.

Please note that Redis's replication is uni-directional. If you want bi-directional replication, you might want to look into Redis Cluster.

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

Switch & save up to 80% 

Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement. Instantly experience up to a 25X boost in performance and 80% reduction in cost