exec.3valkey - Man Page
Executes all commands in a transaction if conditions match.
Synopsis
EXEC [<IFEQ key value | IFNE key value | NX nonexisting-key | XX existing-key>...]
Description
Executes all previously queued commands in a transaction and restores the connection state to normal.
When using WATCH, EXEC will execute commands only if the watched keys were not modified, allowing for a check-and-set mechanism.
Options
EXEC accepts conditions that are checked before the queued commands run, providing optimistic locking without WATCH:
IFEQkey value – Execute only if key holds a string equal to value.IFNEkey value – Execute only if key does not exist, or holds a string different from value.NXkey – Execute only if key does not exist.XXkey – Execute only if key exists.
When multiple conditions are given, all of them must match. If any condition does not match, or if a WATCHed key was modified, the transaction is discarded and EXEC returns a Null reply.
The transaction is discarded and EXEC returns an EXECABORT error if IFEQ or IFNE is used on a key that does not hold a string, if the conditions are malformed, or if the user has no read permission on a condition key. In cluster mode, condition keys must be in the same hash slot as the keys of the queued commands.
Reply
One of the following:
- Array: each element being the reply to each of the commands in the atomic transaction.
- Null: the transaction was aborted because a
WATCHed key was touched or a condition did not match.
Complexity
O(N) for N conditions, plus the complexity of commands in the transaction
Acl Categories
@slow @transaction
History
- Available since: 1.2.0
- Changed in 9.2.0: Added the
IFEQ,IFNE,NX, andXXoptions.
Examples
127.0.0.1:6379> SET version 1 OK 127.0.0.1:6379> MULTI OK 127.0.0.1:6379(TX)> SET version 2 QUEUED 127.0.0.1:6379(TX)> SET data "new data" QUEUED 127.0.0.1:6379(TX)> EXEC IFEQ version 1 1) OK 2) OK 127.0.0.1:6379> MULTI OK 127.0.0.1:6379(TX)> SET version 2 QUEUED 127.0.0.1:6379(TX)> EXEC IFEQ version 1 (nil)
See Also
discard(3valkey), multi(3valkey), unwatch(3valkey), watch(3valkey)