Database / REDIS
What are Redis transactions?
A Redis transaction bundles multiple commands so they execute as a single, uninterrupted sequence — no other client's commands can be interleaved in the middle of a transaction once it starts executing, which is what gives Redis transactions their isolation guarantee.
MULTI SET account:1:balance 100 DECRBY account:1:balance 20 INCRBY account:2:balance 20 EXEC
MULTI begins queuing subsequent commands rather than executing them immediately; EXEC runs the entire queued batch atomically, back to back; DISCARD cancels a queued transaction before it runs. Redis transactions differ from typical relational-database transactions in one important way: there's no mid-transaction rollback for a command that fails at runtime (like a type error) — the rest of the queued commands still execute, and only commands with syntax errors caught at queue time prevent EXEC from running at all. WATCH adds optimistic locking on top, aborting the transaction if a watched key changes before EXEC, which is the standard pattern for implementing check-then-act logic safely.
More Related questions...
