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.
EXEC command do in Redis transactions?MULTI command starts queuing commands, and EXEC runs them all together.EXECEXEC executes all commands queued after MULTI in one atomic operation.MULTI starts the transaction, then commands like SET queue, and finally EXEC runs them.MULTI, then SET, then EXEC.MULTI SET user:1:name "Alice" INCR user:1:visits EXECWhat will be the result of the
EXEC command?SET user:1:name "Alice" sets a string key, returns "OK"; INCR user:1:visits increments a numeric key, returns the new value.EXEC returns an array with results of each command: ["OK", 1].MULTI SET key1 "value1" GET key1 EXECWhat will be the result of the
EXEC command?GET are allowed but return QUEUED during MULTI, and EXEC returns their results after execution.GET is fully supported inside MULTI/EXEC blocks, so EXEC succeeds and returns ["OK", "value1"].WATCH, MULTI, and EXEC to do this safely?WATCH monitors keys for changes before starting a transaction with MULTI.WATCH counter, then MULTI, queue INCR counter, and finally EXEC to run if no changes occurred.Pass the test and this pattern moves unknown