0
0
Redisquery~5 mins

Adding and removing nodes in Redis

Choose your learning style9 modes available
Introduction
Adding and removing nodes helps you grow or shrink your Redis cluster to handle more data or save resources.
When your Redis cluster needs more capacity to store data.
When you want to improve performance by distributing load.
When you want to remove a faulty or old node from the cluster.
When you want to save costs by reducing the number of nodes.
When you are scaling your application up or down.
Syntax
Redis
redis-cli --cluster add-node <new-node-ip>:<port> <existing-node-ip>:<port>
redis-cli --cluster del-node <existing-node-ip>:<port> <node-id>
Use : to specify the new node you want to add.
Use : to specify a node already in the cluster.
Node ID is a unique identifier for each node in the cluster.
Examples
Adds a new node at 192.168.1.10:7003 to the cluster that already has a node at 192.168.1.10:7000.
Redis
redis-cli --cluster add-node 192.168.1.10:7003 192.168.1.10:7000
Removes the node with ID 07c37dfeb2352e03a1b7f4a1a3e8f9c8b7d6a1f2 from the cluster using the node at 192.168.1.10:7000 as reference.
Redis
redis-cli --cluster del-node 192.168.1.10:7000 07c37dfeb2352e03a1b7f4a1a3e8f9c8b7d6a1f2
Sample Program
First, this command adds a new node at 127.0.0.1:7003 to the cluster that already has a node at 127.0.0.1:7000. Then, it removes a node by its ID from the cluster.
Redis
redis-cli --cluster add-node 127.0.0.1:7003 127.0.0.1:7000
redis-cli --cluster del-node 127.0.0.1:7000 07c37dfeb2352e03a1b7f4a1a3e8f9c8b7d6a1f2
OutputSuccess
Important Notes
Always use a node already in the cluster as a reference when adding or removing nodes.
Removing a node will migrate its data to other nodes if needed.
Make sure the new node is running Redis and reachable before adding.
Summary
Adding nodes helps your cluster grow and handle more data.
Removing nodes helps you shrink the cluster or remove bad nodes.
Use redis-cli with --cluster add-node and --cluster del-node commands.