Executes all commands in a transaction if conditions match.
EXEC
[<IFEQ key value |
IFNE key value |
NX nonexisting-key |
XX existing-key>…]
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.
EXEC accepts conditions that are checked before the
queued commands run, providing optimistic
locking without WATCH:
IFEQ key value – Execute only if
key holds a string equal to value.IFNE key value – Execute only if
key does not exist, or holds a string different from
value.NX key – Execute only if key does not
exist.XX key – 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.
One of the following:
WATCHed key
was touched or a condition did not match.O(N) for N conditions, plus the complexity of commands in the transaction
@slow @transaction
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)
IFEQ, IFNE,
NX, and XX options.