Introduction
WATCH helps prevent conflicts when many people try to change the same data at the same time.
WATCH key1 [key2 ...] MULTI commands EXEC UNWATCH
WATCH mykey MULTI INCR mykey EXEC
WATCH user:123:balance MULTI DECRBY user:123:balance 10 EXEC
WATCH cart:456 MULTI HSET cart:456 item "apple" EXEC
WATCH counter MULTI INCR counter EXEC
WATCH command in Redis optimistic locking?counter using optimistic locking?WATCH balance MULTI INCR balance EXEC
balance after WATCH but before EXEC, what will be the result of EXEC?WATCH stock MULTI DECR stock EXEC
Pass the test and this pattern moves unknown