# DISCARD

> Discard queued commands.

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

It also clears every key watched with [`WATCH`](/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
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
MULTI
SET balance 100
DISCARD
```

</Accordion>

<Accordion title="ioredis" icon="node-js" iconType="brands">

```ts
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
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
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
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
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
fn main() -> redis::RedisResult<()> {
    let mut transaction = redis::pipe();
    transaction.atomic().set("balance", "100");
    transaction.clear();
    Ok(())
}
```

</Accordion>

</AccordionGroup>
