EXEC
EXEC
- Group
- Transactions
- Complexity
- The sum of the queued commands' complexities
- Arity
- 1 (exactly, counting the command name)
- Flags
- slow
- HotKV Cloud
- All plans
- On-Premise
- no license needed
EXEC runs every command queued since MULTI, in order,
without commands from other clients in between, and returns their replies as
one array. Afterwards the connection leaves the transaction and all keys
watched with WATCH are unwatched.
The transaction does not run at all when:
- a command was refused while being queued:
EXECreplies withEXECABORT Transaction discarded because of previous errors.; - a watched key was changed by another client (or expired) after
WATCH:EXECreplies with a null and nothing is run.
If a queued command fails while running (for example INCR on a key that does
not hold an integer), its place in the reply array holds the error and the
other commands still run. Nothing is rolled back.
Permissions are checked again for each command when EXEC runs; a command
that the user’s ACL rules no longer allow fails with a NOPERM error in the
reply array.
Return value
Section titled “Return value”| Case | RESP2 | RESP3 |
|---|---|---|
| The transaction ran | Array: one reply per queued command | Array |
| A watched key changed | Nil array | Null |
| A command was refused while queuing | Error EXECABORT ... |
Error |
No MULTI was sent |
Error ERR EXEC without MULTI |
Error |
Examples
Section titled “Examples”127.0.0.1:6379> SET name "ada"OK127.0.0.1:6379> MULTIOK127.0.0.1:6379(TX)> INCR counterQUEUED127.0.0.1:6379(TX)> INCR nameQUEUED127.0.0.1:6379(TX)> EXEC1) (integer) 12) (error) ERR value is not an integer or out of rangeA transaction guarded by WATCH, after another client changed balance:
127.0.0.1:6379> WATCH balanceOK127.0.0.1:6379> MULTIOK127.0.0.1:6379(TX)> DECRBY balance 30QUEUED127.0.0.1:6379(TX)> EXEC(nil)Compatibility
Section titled “Compatibility”Same as Redis 7 and Valkey 8.
See also
Section titled “See also”Was this page helpful?
Thanks for the feedback.