Question: How can Redis Cluster be scaled horizontally?
Answer
Redis cluster provides a way to run a Redis installation where data is automatically sharded across multiple Redis nodes. Horizontal scaling, which is the process of adding more nodes to the system to improve performance and space, is one of the key features of Redis Cluster.
To horizontally scale a Redis Cluster, you need to add new nodes to the cluster and rebalance your data. Here's a basic example:
- Adding a new node
A new node can be added using the
redis-cli
tool provided by Redis.
redis-cli --cluster add-node <new-node-ip>:<new-node-port> <existing-node-ip>:<existing-node-port>
- Rebalancing data Once you've added a new node, you will need to move some data to it, effectively distributing your data more evenly across all available nodes (sharding). You do this with the 'res-hard' option:
redis-cli --cluster rebalance --use-empty-masters <any-node-ip>:<any-node-port>
This command moves keys from the most populated nodes to the least populated ones, trying to get an even distribution.
Make sure to monitor your application during this process as it might impact its performance. It's generally recommended to do such operations during periods of low load or in a maintenance window.
Also, note that Redis Cluster does not support automatic resharding, meaning when you add or remove nodes, you'll have to manually reshard the data.
Was this content helpful?
Other Common Redis Questions (and Answers)
Free System Design on AWS E-Book
Download this early release of O'Reilly's latest cloud infrastructure e-book: System Design on AWS.
Start building today
Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement.