Atomic grouped updates
Update several related keys as one uninterrupted operation.
Redis · Command
MULTI starts a Redis transaction and queues later commands on the current connection. EXEC runs the queued commands atomically, while DISCARD cancels them.
MULTI switches the current connection into transaction mode. Commands sent afterward are queued rather than run immediately, and EXEC later runs the queued commands as one atomic batch; DISCARD can instead clear the queue and leave transaction mode.
MULTISimple string reply: OK.
MULTI
SET cache:user:42 "Ada"
INCR stats:users
EXECStarts a transaction, queues two commands, then executes them atomically with EXEC.
Update several related keys as one uninterrupted operation.
Batch commands that must be committed together.
Pair with WATCH when writes depend on a prior read.
MULTI marks the beginning of a Redis transaction and changes the connection into transaction mode. Subsequent commands are queued, and EXEC executes them as a group.
Follow-up: How can a client cancel the transaction? Send DISCARD; it removes the queued commands and restores the connection to normal mode.
MULTI itself returns the simple string reply OK. Commands issued after MULTI normally return QUEUED because Redis schedules them for execution at EXEC.
Follow-up: When are the commands' actual results available? EXEC returns the results after the queued commands run.
MULTI has O(1) time complexity and was introduced in Redis Open Source 1.2.0. Its syntax is simply MULTI, with no arguments.
Follow-up: Which related commands complete or cancel the transaction? EXEC commits the queued commands, while DISCARD aborts them.
EXECDISCARDWATCH