# UNWATCH

> Unwatch all keys.

Use `UNWATCH` to forget all the keys watched with [`WATCH`](/redis/commands/transactions/watch) on this connection.

Afterwards the next [`EXEC`](/redis/commands/transactions/exec) is no longer conditional on those keys. It is the way to abandon an optimistic locking attempt when, after reading the watched data, you decide not to run a transaction at all, so a later unrelated transaction is not aborted by a change to keys you no longer care about. [`EXEC`](/redis/commands/transactions/exec) and [`DISCARD`](/redis/commands/transactions/discard) clear watches on their own.

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
UNWATCH
```

## 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
UNWATCH
```

</Accordion>

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

```ts
import Redis from "ioredis";

const client = new Redis(process.env.REDIS_URL!);
await client.watch("balance");
await client.unwatch();
```

</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.watch("balance");
await client.unwatch();
```

</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() as pipe:
    pipe.watch("balance")
    pipe.unwatch()
```

</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)

err = client.Watch(ctx, func(tx *redis.Tx) error {
    return tx.Unwatch(ctx).Err()
}, "balance")
if err != nil { panic(err) }
```

</Accordion>

<Accordion title="jedis" icon="java" iconType="brands">

```java
import java.net.URI;
import redis.clients.jedis.Jedis;

try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) {
  jedis.watch("balance");
  jedis.unwatch();
}
```

</Accordion>

<Accordion title="redis-rs" icon="rust" iconType="brands">

```rust
fn main() -> redis::RedisResult<()> {
    let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set");
    let client = redis::Client::open(url)?;
    let mut connection = client.get_connection()?;

    redis::transaction(&mut connection, &["balance"], |_con, _pipe| {
        Ok(Some(()))
    })?;
    Ok(())
}
```

</Accordion>

</AccordionGroup>
