Redis › Transactions
How do you cancel a queued Redis transaction before it executes, and what command is used for this?
BeginnerAnswer
You use the DISCARD command, which cancels the current transaction and clears all commands that were queued after MULTI was called, returning the connection to its normal state without executing any of the queued commands.
MULTI
SET temp_key 'value'
DISCARDReal-world example An application starts building a transaction but decides midway through, based on some application logic, that the operation should not proceed, so it calls DISCARD to safely cancel everything queued so far.