0
0
Redisquery~10 mins

Client-side cluster support in Redis - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Client-side cluster support
Client starts
Fetch cluster slots info
Build slots-to-node map
Send command to correct node based on key hash
Receive response
If MOVED or ASK error
Update slots map
Retry command if needed
End
The client fetches cluster slot info, maps keys to nodes, sends commands to the right node, handles redirects, and updates its map as needed.
Execution Sample
Redis
CLUSTER SLOTS
SET key1 value1
GET key1
Client fetches cluster slots, then sets and gets a key routed to the correct node.
Execution Table
StepActionCommand SentNode TargetedResponseClient Map Update
1Fetch cluster slots infoCLUSTER SLOTSAny nodeSlots info with node rangesBuild slots-to-node map
2Send SET commandSET key1 value1Node for key1 slotOKNo change
3Send GET commandGET key1Node for key1 slotvalue1No change
4If MOVED or ASK error receivedRetry commandUpdated nodeOK or value1Update slots-to-node map
5Return final responseN/AN/Avalue1N/A
💡 Commands complete successfully or after handling MOVED redirects and updating client map.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4Final
slots_to_node_mapemptypopulated with slot ranges and nodesunchangedunchangedupdated if MOVED or ASK errorfinal updated map
commandnonenoneSET key1 value1GET key1retry if needednone
responsenoneslots infoOKvalue1OK or value1value1
Key Moments - 3 Insights
Why does the client need to fetch cluster slots info first?
The client uses the slots info to know which node holds which key range, so it can send commands directly to the correct node (see execution_table step 1).
What happens if the client sends a command to the wrong node?
The server replies with a MOVED or ASK error, prompting the client to update its slots map and retry the command on the correct node (see execution_table step 4).
Does the client update its slots map after every command?
No, it updates only when it receives a MOVED or ASK error indicating the cluster topology changed (see execution_table steps 4 and 5).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, at which step does the client build the slots-to-node map?
AStep 2
BStep 3
CStep 1
DStep 4
💡 Hint
Check the 'Client Map Update' column in execution_table row for Step 1.
According to variable_tracker, what is the state of 'response' after Step 3?
A"OK"
B"value1"
C"slots info"
D"none"
💡 Hint
Look at the 'response' row and the 'After Step 3' column in variable_tracker.
If the client receives a MOVED error, what does it do next according to the execution_table?
AUpdate slots map and retry command
BIgnore and return error to user
CRestart cluster
DSend command to random node
💡 Hint
See execution_table step 4 under 'Client Map Update' and 'Action'.
Concept Snapshot
Client-side cluster support:
- Client fetches cluster slots info with CLUSTER SLOTS.
- Builds a map of slots to nodes.
- Routes commands to correct node based on key hash slot.
- Handles MOVED/ASK errors by updating map and retrying.
- Ensures commands reach correct node without server-side proxy.
Full Transcript
Client-side cluster support in Redis means the client first asks the cluster for slot information using the CLUSTER SLOTS command. This tells the client which node is responsible for which key ranges. The client then builds a map from slots to nodes. When the client sends commands like SET or GET, it calculates the key's slot and sends the command directly to the correct node. If the client sends a command to the wrong node, the server replies with a MOVED or ASK error. The client then updates its slots map and retries the command on the right node. This process ensures efficient routing of commands in a Redis cluster without extra server-side proxying.