> ## Documentation Index
> Fetch the complete documentation index at: https://upstash.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# DISCARD

> Discard queued commands.

Use `DISCARD` to throw away the commands queued since [`MULTI`](/docs/redis/commands/transactions/multi) and leave the transaction without running anything.

It also clears every key watched with [`WATCH`](/docs/redis/commands/transactions/watch), so the connection ends up in its normal state. This is what you call when the data you read after `WATCH` turns out to make the queued update unnecessary or invalid.

The raw command is TCP-only. Over HTTP, use the transaction or pipeline API of an Upstash SDK instead of sending this command directly.

## Syntax

```redis theme={"system"}
DISCARD
```

## Arguments

This command takes no arguments.

## Important points

* The raw command is TCP-only. For HTTP, use an Upstash SDK transaction API rather than sending this command directly.

## Response

The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below.

| Protocol | Reply              |
| -------- | ------------------ |
| RESP2    | Simple string `OK` |
| RESP3    | Simple string `OK` |

<Note>
  Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply.
</Note>

## Examples

TCP examples use the TLS `REDIS_URL` from the Upstash console. REST examples use `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`.

<AccordionGroup>
  <Accordion title="Redis CLI" icon="terminal">
    ```bash theme={"system"}
    MULTI
    SET balance 100
    DISCARD
    ```
  </Accordion>

  <Accordion title="ioredis" icon="node-js" iconType="brands">
    ```ts theme={"system"}
    import Redis from "ioredis";

    const client = new Redis(process.env.REDIS_URL!);
    await client.multi({ pipeline: false });
    await client.set("balance", "100");
    await client.discard();
    ```
  </Accordion>

  <Accordion title="node-redis" icon="node-js" iconType="brands">
    ```ts theme={"system"}
    import { createClient } from "redis";

    const client = await createClient({ url: process.env.REDIS_URL }).connect();
    await client.sendCommand(["MULTI"]);
    await client.sendCommand(["SET", "balance", "100"]);
    await client.sendCommand(["DISCARD"]);
    ```
  </Accordion>

  <Accordion title="redis-py" icon="python" iconType="brands">
    ```python theme={"system"}
    import os
    import redis

    client = redis.from_url(os.environ["REDIS_URL"])
    with client.pipeline(transaction=True) as pipe:
        pipe.set("balance", "100")
        pipe.reset()
    ```
  </Accordion>

  <Accordion title="go-redis" icon="golang" iconType="brands">
    ```go theme={"system"}
    ctx := context.Background()
    opts, err := redis.ParseURL(os.Getenv("REDIS_URL"))
    if err != nil { panic(err) }
    client := redis.NewClient(opts)

    pipe := client.TxPipeline()
    pipe.Set(ctx, "balance", "100", 0)
    pipe.Discard()
    ```
  </Accordion>

  <Accordion title="jedis" icon="java" iconType="brands">
    ```java theme={"system"}
    import java.net.URI;
    import redis.clients.jedis.Jedis;
    import redis.clients.jedis.Transaction;

    try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")));
         Transaction transaction = jedis.multi()) {
      transaction.set("balance", "100");
      transaction.discard();
    }
    ```
  </Accordion>

  <Accordion title="redis-rs" icon="rust" iconType="brands">
    ```rust theme={"system"}
    fn main() -> redis::RedisResult<()> {
        let mut transaction = redis::pipe();
        transaction.atomic().set("balance", "100");
        transaction.clear();
        Ok(())
    }
    ```
  </Accordion>
</AccordionGroup>


## Related topics

- [Transactions commands](/docs/redis/commands/transactions/overview.md)
- [RESET](/docs/redis/commands/connection/reset.md)
- [JSON.ARRTRIM](/docs/redis/commands/json/json-arrtrim.md)
- [REST API](/docs/redis/features/restapi.md)
- [UNWATCH](/docs/redis/commands/transactions/unwatch.md)
