Skip to content

Ask the HotKV docs

Answers come only from these docs and can be wrong; check the linked pages before you rely on them.

EXEC

Last updated
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: EXEC replies with EXECABORT Transaction discarded because of previous errors.;
  • a watched key was changed by another client (or expired) after WATCH: EXEC replies 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.

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
127.0.0.1:6379> SET name "ada"
OK
127.0.0.1:6379> MULTI
OK
127.0.0.1:6379(TX)> INCR counter
QUEUED
127.0.0.1:6379(TX)> INCR name
QUEUED
127.0.0.1:6379(TX)> EXEC
1) (integer) 1
2) (error) ERR value is not an integer or out of range

A transaction guarded by WATCH, after another client changed balance:

127.0.0.1:6379> WATCH balance
OK
127.0.0.1:6379> MULTI
OK
127.0.0.1:6379(TX)> DECRBY balance 30
QUEUED
127.0.0.1:6379(TX)> EXEC
(nil)

Same as Redis 7 and Valkey 8.

MULTI, DISCARD, WATCH