Question: How can one scale a Redis cluster?


Scaling a Redis Cluster involves increasing or decreasing the number of nodes (masters or replicas) to handle more data or traffic. There are two primary methods for scaling a Redis cluster: vertical scaling and horizontal scaling.

Vertical Scaling refers to adding more power (CPU, RAM) to an existing node (master or replica). This method is easier but has its limits in hardware capacities. It's also not advisable for systems requiring high availability because it introduces single points of failure.

# To alter the resources of a node, you'll likely need to restart Redis with a new configuration. redis-cli -h <hostname> -p <port> SHUTDOWN

Then start Redis again using your new configuration file:

redis-server /path/to/new/redis.conf

Horizontal Scaling means distributing your dataset across multiple nodes. In the context of Redis, this is done by partitioning your data across more masters. Each master might have one or more replicas. You create more slots on new master nodes, moving some slots from current ones to the newly created nodes.

When adding a new node to the Redis Cluster:

  1. Start a new Redis instance:
redis-server --appendonly yes --cluster-enabled yes --cluster-config-file nodes-6379.conf --cluster-node-timeout 5000 --dbfilename dump-6379.rdb --port 6379 --tcp-backlog 511 --timeout 0 --daemonize yes
  1. Use the CLUSTER MEET command to introduce the new node to the cluster:
redis-cli -h <new_node_host> -p <new_node_port> CLUSTER MEET <existing_node_ip> <existing_node_port>
  1. Rebalance the keys among the old and new nodes using the CLUSTER REBALANCE command:
redis-cli --cluster rebalance --cluster-use-empty-masters <any_cluster_node_ip>:<port>

Note: Be sure to replace placeholders (like <new_node_host>, <new_node_port> etc.) with actual values appropriate for your setup.

Remember, while scaling a Redis cluster, you should ensure that each master node has at least one slave node in order to provide failover support in case of a master node failure.

Keep in mind, the specifics can vary based on the environment (cloud provider, containerization, etc.), and the exact commands may change over time, so always consult the most recent official Redis documentation.

Was this content helpful?

Start building today

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