DISCARD

Since 1.1.0Transactions

Syntax

DISCARD
  • Flags: fast
  • ACL categories: @fast, @transaction
  • Arity: 1

Ends a transaction without running it: the commands queued since MULTI are dropped, none of them runs, and the connection is back to running each command as it is sent. Use it when the client decides, part way through queuing, not to go on, or to get out of a transaction a queuing error has already doomed: after an unknown command or wrong arguments, EXEC would only reply EXECABORT.

DISCARD also ends every WATCH of the connection, as EXEC does. Outside a transaction it is an error, and leaves the watches as they are: use UNWATCH there. It takes no arguments: DISCARD x is ERR wrong number of arguments for 'discard' command, as in Redis, since 1.2.1; 1.2.0 ignored them.

See Transactions.

Reply

  • OK.
  • ERR DISCARD without MULTI outside a transaction.

Examples

> MULTI
OK
> SET z 1
QUEUED
> INCR z
QUEUED
> DISCARD
OK
> EXISTS z
(integer) 0
> DISCARD
(error) ERR DISCARD without MULTI

After a queuing error:

> MULTI
OK
> SET z 1
QUEUED
> NOSUCHCMD
(error) ERR unknown command 'NOSUCHCMD', with args beginning with: 
> DISCARD
OK