Cluster architecture in Redis - Mini Project: Build & Apply
redis-node-7000.conf, redis-node-7001.conf, and redis-node-7002.conf. Each file should have the line port 7000, port 7001, and port 7002 respectively, and include cluster-enabled yes to enable clustering.Each Redis node configuration file must specify its unique port and enable clustering with cluster-enabled yes.
redis-cli --cluster create 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 --cluster-replicas 0 to create the cluster without replicas.Use redis-server to start each node with its config file. Then run the redis-cli --cluster create command with all node addresses and --cluster-replicas 0 to create the cluster without replicas.
redis-cli -p 7000 cluster slots to check the slot allocation.Use redis-cli -p 7000 cluster slots to see how slots are distributed among the nodes.
redis-cli -p 7000 cluster nodes to list all nodes in the cluster and verify they are connected and communicating properly.Run redis-cli -p 7000 cluster nodes to see all cluster nodes and their status.
Practice
What is the main purpose of Redis Cluster architecture?
Solution
Step 1: Understand Redis Cluster design
Redis Cluster splits data across multiple servers using hash slots to distribute load.Step 2: Identify the main benefit
This splitting improves speed, storage capacity, and fault tolerance by avoiding a single point of failure.Final Answer:
To split data across multiple servers for better performance and fault tolerance -> Option DQuick Check:
Redis Cluster = Data distribution + fault tolerance [OK]
- Thinking Redis Cluster stores data on one server
- Confusing cluster with encryption feature
- Assuming cluster only handles backups
Which command line option is required to start a Redis node with cluster enabled?
redis-server --port 7000 --cluster-enabled ???
Solution
Step 1: Recall Redis cluster start syntax
To enable cluster mode, the option is--cluster-enabled yes.Step 2: Confirm correct boolean value
Redis expects 'yes' or 'no' for this flag, not 'true', 'on', or 'enable'.Final Answer:
yes -> Option AQuick Check:
Cluster enabled flag = yes [OK]
- Using 'true' or 'on' instead of 'yes'
- Typing 'enable' which is invalid
- Omitting the cluster-enabled option
Given a Redis Cluster with 3 nodes, each handling 5461 hash slots, what happens if one node fails?
Choose the correct behavior:
Solution
Step 1: Understand Redis Cluster fault tolerance
Redis Cluster uses replicas to provide fault tolerance. If a node fails, replicas can take over its hash slots.Step 2: Analyze failure impact
If replicas exist, the cluster continues working by promoting replicas. Without replicas, cluster availability is affected.Final Answer:
The cluster continues working if replicas exist for the failed node's slots -> Option CQuick Check:
Node failure + replicas = cluster stays up [OK]
- Assuming cluster stops immediately on node failure
- Thinking data is lost without replicas
- Believing cluster merges slots automatically
Identify the error in this Redis cluster node start command:
redis-server --port 7001 --cluster-enabled yes --cluster-config-file nodes-7001.conf --cluster-node-timeout 5000 --cluster-announce-ip 192.168.1.10 --cluster-announce-port 7001 --cluster-announce-bus-port 17001 --cluster-enabled no
Solution
Step 1: Review cluster-enabled flags
The command has two--cluster-enabledflags: one set to 'yes' and another to 'no'. This is conflicting.Step 2: Understand impact of conflicting flags
Redis will use the last flag, disabling cluster mode, which contradicts other cluster options.Final Answer:
The command has conflicting cluster-enabled flags -> Option AQuick Check:
Conflicting flags cause cluster mode error [OK]
- Ignoring repeated flags causing conflicts
- Assuming port 7001 is invalid
- Thinking config file name causes error
You want to create a Redis Cluster with 6 nodes: 3 masters and 3 replicas. Which of the following is the correct approach to assign hash slots and replicas?
Solution
Step 1: Understand hash slot distribution
Redis Cluster has 16384 hash slots. These should be evenly split among master nodes for balanced load.Step 2: Assign replicas properly
Each replica should be linked to a different master to provide fault tolerance and avoid single points of failure.Final Answer:
Assign all 16384 hash slots evenly to 3 masters; assign each replica to a different master node -> Option BQuick Check:
Slots evenly on masters + replicas assigned = correct cluster setup [OK]
- Assigning slots to replicas instead of masters
- Not linking replicas to masters
- Putting all slots on one master only
Ready to prove it?
Pass the test and this pattern moves unknown
