Question: How can one scale out a Redis cluster?


Scaling out a Redis Cluster involves adding more nodes to handle an increase in data or traffic. It's a way of distributing the load across multiple servers, thereby increasing the capacity and performance of your application.

Here are the steps to follow:

  1. Create new Redis instances: On new machines or existing machines with enough resources, create new Redis instances. The number of instances you'll need depends on the size and requirements of your application.
redis-server --port 7006
redis-server --port 7007
  1. Add the new nodes to the cluster: Use the cluster meet command to add each new node to the cluster. You do this by connecting to an existing node and using it to introduce the new node to the cluster.
redis-cli -p 7000 cluster meet 7006
redis-cli -p 7000 cluster meet 7007
  1. Assign slots to the new nodes: Once the new nodes have been added to the cluster, you need to assign them some hash slots. This distributes the data evenly across all the available nodes.
redis-cli -p 7006 cluster addslots {0..5000}
redis-cli -p 7007 cluster addslots {5001..10000}
  1. Rebalance the cluster: After assigning slots to the new nodes, rebalance the cluster so that the data is evenly distributed across all nodes. This process may take some time depending on the amount of data that needs to be moved. Redis provides a redis-cli --cluster rebalance command to help with this.
redis-cli --cluster rebalance
  1. Check the cluster state: Finally, check the state of your cluster to ensure everything is correctly configured and balanced.
redis-cli -p 7000 cluster info

Remember, adding nodes to a Redis cluster and re-distributing the data this way is a complex process that requires careful planning. It's important to monitor your cluster before and after scaling out to ensure that the operation has been successful and your application continues to function as expected.

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.