Introduction
EXEC runs all the commands queued in a transaction together. It helps make sure multiple commands happen at the same time.
MULTI ...commands... EXEC
MULTI SET key1 value1 SET key2 value2 EXEC
MULTI INCR counter INCR counter EXEC
MULTI SET user:1:name "Alice" SET user:1:age 30 EXEC
EXEC command do in Redis transactions?MULTI command starts queuing commands, and EXEC runs them all together.EXECEXEC executes all commands queued after MULTI in one atomic operation.MULTI starts the transaction, then commands like SET queue, and finally EXEC runs them.MULTI, then SET, then EXEC.MULTI SET user:1:name "Alice" INCR user:1:visits EXECWhat will be the result of the
EXEC command?SET user:1:name "Alice" sets a string key, returns "OK"; INCR user:1:visits increments a numeric key, returns the new value.EXEC returns an array with results of each command: ["OK", 1].MULTI SET key1 "value1" GET key1 EXECWhat will be the result of the
EXEC command?GET are allowed but return QUEUED during MULTI, and EXEC returns their results after execution.GET is fully supported inside MULTI/EXEC blocks, so EXEC succeeds and returns ["OK", "value1"].WATCH, MULTI, and EXEC to do this safely?WATCH monitors keys for changes before starting a transaction with MULTI.WATCH counter, then MULTI, queue INCR counter, and finally EXEC to run if no changes occurred.Pass the test and this pattern moves unknown