Concept Flow - EXEC to execute
Start Transaction with MULTI
Queue Commands
Call EXEC
Execute All Queued Commands
Return Array of Results
End
This flow shows how Redis queues commands after MULTI and executes them all at once when EXEC is called.
MULTI
SET key1 "Hello"
INCR counter
EXEC| Step | Command | Action | Result | Notes |
|---|---|---|---|---|
| 1 | MULTI | Start transaction mode | OK | Commands will be queued, not executed immediately |
| 2 | SET key1 "Hello" | Queue command | QUEUED | Command added to transaction queue |
| 3 | INCR counter | Queue command | QUEUED | Command added to transaction queue |
| 4 | EXEC | Execute all queued commands | ["OK", 1] | Returns results of SET and INCR commands |
| 5 | - | Transaction ends | - | All commands executed atomically |
| Variable | Start | After MULTI | After SET queued | After INCR queued | After EXEC | Final |
|---|---|---|---|---|---|---|
| transaction_mode | off | on | on | on | off | off |
| command_queue | empty | empty | [SET key1 "Hello"] | [SET key1 "Hello", INCR counter] | empty | empty |
| key1 | nil | nil | nil | nil | "Hello" | "Hello" |
| counter | nil | nil | nil | nil | 1 | 1 |
MULTI starts a transaction, queuing commands. Commands return QUEUED until EXEC. EXEC runs all queued commands atomically. EXEC returns an array of results. Transaction ends after EXEC.