0
0
Redisquery~10 mins

Cluster architecture in Redis - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Cluster architecture
Client calculates key slot
Client sends command to correct node
Node processes command
Return result to client
The client calculates the slot for the key, determines the correct node, sends the command directly there, and receives the result.
Execution Sample
Redis
SET user:1 "Alice"
GET user:1
DEL user:1
Commands to set, get, and delete a key in a Redis cluster, showing routing and execution.
Execution Table
StepActionKeySlot CalculationNode ChosenResult
1Client sends SET commanduser:1Calculate slot for 'user:1' (e.g. slot 1234)Node A (owns slot 1234)Sent to Node A
2Node A executes SETuser:1Slot 1234Node AOK
3Client sends GET commanduser:1Calculate slot for 'user:1' (slot 1234)Node ASent to Node A
4Node A executes GETuser:1Slot 1234Node A"Alice"
5Client sends DEL commanduser:1Calculate slot for 'user:1' (slot 1234)Node ASent to Node A
6Node A executes DELuser:1Slot 1234Node A1 (deleted)
7Client sends GET commanduser:1Calculate slot for 'user:1' (slot 1234)Node ASent to Node A
8Node A executes GETuser:1Slot 1234Node A(nil)
9End of commandsNo more commands to process
💡 All commands processed; cluster routes commands based on key slots to correct nodes.
Variable Tracker
VariableStartAfter Step 2After Step 4After Step 6After Step 8
user:1does not exist"Alice""Alice"deleteddoes not exist
Key Moments - 2 Insights
Why does the client need to calculate the slot before sending the command?
The client must calculate the slot to send the command directly to the right node (see execution_table steps 1, 3, 5).
What happens if the key does not exist on the node?
The node returns nil or 0 depending on the command, as shown in step 8 where GET returns (nil) after the key was deleted in step 6.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 4, what is the result of the GET command?
AOK
B"Alice"
C1 (deleted)
D(nil)
💡 Hint
Check the 'Result' column at step 4 in the execution_table.
At which step does the key 'user:1' get deleted from the cluster?
AStep 6
BStep 4
CStep 2
DStep 8
💡 Hint
Look at the 'Action' and 'Result' columns in the execution_table to find when DEL is executed.
If the client did not calculate the slot, what would happen?
AThe command would be ignored
BThe cluster would automatically find the correct node without issue
CThe client would receive an error immediately
DThe command would be routed to the wrong node and fail
💡 Hint
Refer to the concept_flow showing the importance of slot calculation before sending to the node.
Concept Snapshot
Redis Cluster distributes data by key slots.
Client calculates slot from key.
Slot determines which node handles the command.
Commands are sent directly to the correct node.
Nodes execute commands and return results.
This ensures data is distributed and accessible.
Full Transcript
In Redis Cluster architecture, when a client sends a command involving a key, it first calculates the key's slot. This slot number determines which node in the cluster owns the data for that key. The client then sends the command directly to that node. The node executes the command and returns the result to the client. For example, setting a key 'user:1' involves calculating its slot, routing the SET command to the correct node, storing the value, and confirming success. Later GET and DEL commands follow the same routing process. If the key is deleted, subsequent GET commands return nil. This process ensures efficient data distribution and retrieval across the cluster.