# MULTI

> Start a transaction.

Use `MULTI` to start a transaction.

Commands sent afterwards are not executed but queued, each answered with `QUEUED`, until [`EXEC`](/redis/commands/transactions/exec) runs them all in order with nothing else in between, or [`DISCARD`](/redis/commands/transactions/discard) throws them away.

A Redis transaction is atomic in the sense that no other client sees a partial result, but it is not a rollback mechanism: a command that fails at queue time, such as one with a syntax error, aborts the whole transaction, while a command that fails at execution time, such as one applied to the wrong type, leaves the commands around it applied. Combine it with [`WATCH`](/redis/commands/transactions/watch) when the transaction depends on values you read beforehand.

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

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

</Accordion>

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

```ts
import Redis from "ioredis";

const client = new Redis(process.env.REDIS_URL!);
const result = await client.multi().set("balance", "100").exec();
```

</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();
const result = await client.multi().set("balance", "100").exec();
```

</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:
    result = pipe.set("balance", "100").execute()
```

</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)
result, err := pipe.Exec(ctx)
if err != nil { panic(err) }
```

</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");
  Object result = transaction.exec();
}
```

</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::pipe()
        .atomic()
        .set("balance", "100")
        .ignore()
        .query::<()>(&mut connection)?;
    Ok(())
}
```

</Accordion>

</AccordionGroup>
