📖 Scenario: You are managing a Redis cluster for a growing online store. The cluster needs to be updated by adding a new node to handle more traffic and removing an old node that is no longer needed.
🎯 Goal: Learn how to add a new node to a Redis cluster and remove an existing node using Redis CLI commands.
📋 What You'll Learn
Create a Redis cluster with three nodes
Add a new node to the existing cluster
Remove an existing node from the cluster
Verify the cluster nodes after each operation
💡 Why This Matters
🌍 Real World
Managing Redis clusters is essential for scaling applications that require fast data access and high availability.
💼 Career
Database administrators and backend engineers often need to add or remove nodes in Redis clusters to maintain performance and reliability.
Progress0 / 4 steps
1
Create a Redis cluster with three nodes
Use the Redis CLI command redis-cli --cluster create with the exact node addresses 127.0.0.1:7000, 127.0.0.1:7001, and 127.0.0.1:7002 to create a cluster. Include the --cluster-replicas 0 option to create no replicas.
Redis
Hint
Use redis-cli --cluster create followed by the three node addresses and --cluster-replicas 0.
2
Add a new node to the existing cluster
Use the Redis CLI command redis-cli --cluster add-node to add the new node 127.0.0.1:7003 to the cluster. Specify the existing cluster node 127.0.0.1:7000 as the target for the join.
Redis
Hint
Use redis-cli --cluster add-node 127.0.0.1:7003 127.0.0.1:7000 to add the new node.
3
Remove an existing node from the cluster
Use the Redis CLI command redis-cli --cluster del-node to remove the node 127.0.0.1:7001 from the cluster. You need to specify the cluster node 127.0.0.1:7000 and the node ID of 127.0.0.1:7001. For this exercise, use the placeholder node ID node-id-7001 exactly as shown.
Redis
Hint
Use redis-cli --cluster del-node 127.0.0.1:7000 node-id-7001 to remove the node.
4
Verify the cluster nodes after changes
Use the Redis CLI command redis-cli --cluster nodes with the cluster node 127.0.0.1:7000 to list all nodes currently in the cluster.
Redis
Hint
Use redis-cli --cluster nodes 127.0.0.1:7000 to see the current cluster nodes.
Practice
(1/5)
1. What is the primary purpose of adding nodes to a Redis cluster?
easy
A. To increase the cluster's capacity and distribute data
B. To delete all data from the cluster
C. To backup the cluster data
D. To change the Redis version on all nodes
Solution
Step 1: Understand what adding nodes means
Adding nodes means increasing the number of servers in the cluster to share the data load.
Step 2: Identify the effect of adding nodes
More nodes mean more capacity and better data distribution across the cluster.
Final Answer:
To increase the cluster's capacity and distribute data -> Option A
Quick Check:
Adding nodes = More capacity and distribution [OK]
Hint: Adding nodes grows cluster capacity and data spread [OK]
Common Mistakes:
Thinking adding nodes deletes data
Confusing adding nodes with backup
Assuming adding nodes upgrades Redis version
2. Which of the following is the correct syntax to add a node to a Redis cluster using redis-cli?
easy
A. redis-cli --cluster add-node :<port> :<port>
B. redis-cli --cluster remove-node :<port>
C. redis-cli --cluster create-node :<port>
D. redis-cli --cluster add :<port>
Solution
Step 1: Recall the command to add a node
The correct command uses --cluster add-node followed by the new node and an existing node in the cluster.