ERR
RedisERRORCommonTransactionsHIGH confidence

DISCARD without MULTI

Production Risk

Low. This is a simple protocol violation that is easily caught and fixed.

What this means

This error occurs when a client sends a DISCARD command but is not currently in a transaction state. A transaction must first be initiated with the MULTI command to be discardable.

Why it happens
  1. 1A client library bug where DISCARD is called improperly.
  2. 2A client connection was dropped and reconnected, losing the transaction context, but the application logic tried to DISCARD anyway.
  3. 3Manual execution of DISCARD in a CLI session without first typing MULTI.
How to reproduce

A client sends a DISCARD command on a fresh connection.

trigger — this will error
trigger — this will error
DISCARD

expected output

(error) ERR DISCARD without MULTI

Fix 1

Only call DISCARD within a MULTI block

WHEN When you need to cancel a transaction that has been started

Only call DISCARD within a MULTI block
MULTI
INCR mycounter
DISCARD

Why this works

The DISCARD command is only valid when a transaction has been initiated by MULTI. It flushes the queue of commands and exits the transaction state.

Fix 2

Use a client library's error handling for transactions

WHEN In application code

Use a client library's error handling for transactions
// pseudocode for a library
const tx = client.multi();
try {
  tx.incr('foo');
  // something fails here
  throw new Error();
} catch (e) {
  tx.discard(); // Library correctly calls discard
}

Why this works

Good client libraries will automatically handle calling DISCARD if an error occurs during the queueing phase of a transaction, preventing orphaned transactions and improper calls.

What not to do

Use DISCARD to clear errors

DISCARD only works for cancelling a MULTI block. It has no other function.

Sources
Official documentation ↗

Transaction state machine in connection handling.

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Redis errors