0
0
Redisquery~10 mins

Sending multiple commands in pipeline in Redis - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Sending multiple commands in pipeline
Start Pipeline
Queue Command 1
Queue Command 2
Queue Command N
Send All Commands Together
Receive All Responses
Process Responses
End Pipeline
Commands are queued first, then sent all at once to Redis, responses come back together, improving speed.
Execution Sample
Redis
MULTI
SET key1 value1
SET key2 value2
EXEC
Queues two SET commands in a transaction and executes them together.
Execution Table
StepActionCommand QueuedPipeline StateResponse Received
1Start pipelineNoneEmpty queueNone
2Queue commandSET key1 value1Queue: [SET key1 value1]None
3Queue commandSET key2 value2Queue: [SET key1 value1, SET key2 value2]None
4Send all commandsMULTI, SET key1 value1, SET key2 value2, EXECQueue sentNone
5Receive responsesNoneQueue clearedResponses: [OK, QUEUED, QUEUED, [OK, OK]]
6Process responsesNoneEmpty queueCommands executed successfully
7End pipelineNoneEmpty queuePipeline finished
💡 All queued commands sent and responses received, pipeline ends.
Variable Tracker
VariableStartAfter Step 2After Step 3After Step 4After Step 5Final
pipeline_queue[][SET key1 value1][SET key1 value1, SET key2 value2]Sent to Redis[][]
responses[][][][][OK, QUEUED, QUEUED, [OK, OK]][OK, QUEUED, QUEUED, [OK, OK]]
Key Moments - 2 Insights
Why don't we get responses immediately after queuing each command?
Responses come only after sending all commands together (see step 5 in execution_table), because pipeline queues commands first to send them in bulk.
What happens if we forget to send the queued commands?
Commands stay in the queue and no responses come back (see pipeline_queue state at step 4), so the pipeline never completes.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 3, what is the pipeline state?
AQueue: [SET key1 value1]
BQueue sent
CQueue: [SET key1 value1, SET key2 value2]
DEmpty queue
💡 Hint
Check the 'Pipeline State' column at step 3 in execution_table.
At which step do we receive the responses from Redis?
AStep 5
BStep 4
CStep 2
DStep 7
💡 Hint
Look at the 'Response Received' column in execution_table.
If we add another SET command before sending, how does the pipeline queue change at step 3?
AQueue sent
BQueue: [SET key1 value1, SET key2 value2, SET key3 value3]
CQueue: [SET key1 value1]
DEmpty queue
💡 Hint
Refer to variable_tracker for pipeline_queue changes after queuing commands.
Concept Snapshot
Sending multiple commands in pipeline:
- Queue commands first without waiting for responses.
- Send all queued commands together to Redis.
- Receive all responses at once.
- Improves performance by reducing network delays.
- Use MULTI/EXEC or pipeline commands for batching.
Full Transcript
In Redis, sending multiple commands in a pipeline means you first queue commands without waiting for each response. Once all commands are queued, you send them together to Redis. Redis processes them and sends back all responses at once. This reduces the time spent waiting for each command individually, making operations faster. The example shows queuing two SET commands inside a MULTI/EXEC transaction. The execution table traces each step: starting the pipeline, queuing commands, sending them, receiving responses, and finishing. Variables like the pipeline queue and responses change state as commands are queued and sent. Key points include understanding that responses come only after sending all commands, and forgetting to send commands leaves the queue uncleared. The visual quiz tests understanding of pipeline state and response timing. The snapshot summarizes the main idea: queue commands, send together, get responses together, for better speed.