How to Set Up a Redis Replication Cluster

Updated on January 28, 2022
How to Set Up a Redis Replication Cluster header image


In Redis, replication is a programming model that allows you to implement the key-value store across different machines to improve reliability, fault-tolerance, and accessibility. Instead of relying on a single machine that can fail, you make data redundant across multiple servers. In such a multi-node environment, the failure of one machine in the cluster can not completely stop the operation of the Redis server. When your current primary Redis instance fails, you elect a new one from the remaining nodes participating in the replication process. In this guide, you'll set up a Redis replication on your Ubuntu 20.04 server to provide a high-availabilty cluster for your application.

Note on Naming

  • The Redis project uses the term replica instead of slave, unless required for backward compatibility, starting with version 5.
  • The terms primary and master are synonyms in this article.
  • For more information, see:


To proceed with this guide, ensure you have a set of three Ubuntu 20.04 nodes in the same Vultr location, configured with private networking. This guide uses the following private IP addresses for the nodes.

  • node-1 : Primary node
  • node-2 : Replica node
  • node-3 : Replica node

Each node should have:

1. Verify Redis Installation on All Servers

SSH to all three servers and follow the steps below to make sure the Redis server is installed and active.

  1. Launch the redis-cli package.

     $ redis-cli
  2. Run the ping command.> PING
  3. If the Redis server is running, you should get the following output.> PONG
  4. Press Ctrl + C to log out from the Redis server.

  5. After you have verified the Redis instances are up and running, you can now configure replication settings on them.

2. Configure Redis Server Replication Settings

The Redis server relies on many configuration settings to work in replication mode. You'll have to configure these settings in all the three nodes.

By default, you can locate the Redis configuration settings in the following file.

  1. Use nano to open the file on all three servers for editing purposes.

     $ sudo nano /etc/redis/redis.conf
  2. Make the following configuration changes in all three servers. Remember to replace EXAMPLE_REPL_PASSWORD with a strong password.

    node-1 : Primary node -

     bind ::1
     protected-mode no 
     requirepass EXAMPLE_REPL_PASSWORD

    node-2 : Replica node -

     bind ::1
     protected-mode no 
     replicaof 6379
     requirepass EXAMPLE_REPL_PASSWORD

    node-3 : Replica node -

     bind ::1
     protected-mode no 
     replicaof 6379
     requirepass EXAMPLE_REPL_PASSWORD
  3. Save and close the file when you're through with editing.

  4. Then, execute the following command to restart the Redis server in all three servers.

     $ sudo systemctl restart redis-server
  5. You've correctly configured the Redis instances in all the nodes. In the next step, you'll test the new configuration settings.

3. Test Redis Replication

The following diagram illustrates the Redis replication architecture that you've set up.

    +------------------+      +---------------+  +---------------+
    |     Primary      | ---> |   Replica 1   |  |   Replica 2   |
    | (receive writes) |      |  (exact copy) |  |  (exact copy) |
    +------------------+      +---------------+  +---------------+

Every key you write to the primary Redis server will be automatically copied to the replica instances. To confirm this, execute the following steps.

  1. Log in to the Redis server on the primary node-1 (

     $ redis-cli
  2. Next, authenticate to the Redis server.> AUTH EXAMPLE_REPL_PASSWORD
  3. Execute the following command to view the replication status.> info replication
  4. You should get the following output.

     # Replication
  5. Next, set up a test key with a value of, The key value was set on the primary node..> set test "The key value was set on the primary node."
  6. Ensure you get the confirmation message below.

  7. Opening two new terminal windows. Then, SSH to the replica nodes: node-2 ( and node-3 (

     $ redis-cli
  8. Authenticate to the Redis servers on the replica nodes.> AUTH EXAMPLE_REPL_PASSWORD
  9. Attempt retrieving the value of the test key that you've created on the primary node.> GET test
  10. You should get the following output showing the replication process is working as expected.

     "The key value was set on the primary node."

4. Promoting a Replica to Primary

In case the primary node goes down, you can promote any standby replica node to become the new primary using the following process.

  1. Log in to the Redis server on the replica node. For instance, node-1 (

     $ redis-cli
  2. Authenticate to the Redis server on node-1.> AUTH EXAMPLE_REPL_PASSWORD
  3. Instruct the replica to stop replicating data from the old primary node.> replicaof no one
  4. Log out from the Redis server on the replica node.> QUIT;
  5. Open the Redis configuration file on the replica node and remove the following lines to make Redis run in primary mode.

     replicaof 6379
  6. Save and close the file. Then, restart the Redis server on the new primary.

     $ sudo systemctl restart redis-server
  7. Next, log in to the Redis server on node-2 ( Authenticate and run the command below to instruct the remaining replica node to start replicating from the newly elected primary.> replicaof 6379


  8. On node-2 (, execute the following command to make sure you've adjusted the new primary settings accordingly.> info replication
  9. You should get the following output showing that the new primary is up and running.

     # Replication
  10. From this point forward, you can set the new primary IP address in any app that you'd previously connected to the old primary node.


In this guide, you've configured Redis replication architecture. Use the settings in this guide to implement a fault-tolerant environment for your Redis use case.

Visit the following resources to learn more about implementing Redis in your applications.