# EXEC

> Run all commands queued since MULTI as one transaction.

URL: https://docs.hotkv.com/commands/exec/

```
EXEC
```

- Group: Transactions
- Complexity: The sum of the queued commands' complexities
- HotKV Cloud: all plans
- On-Premise: no license needed

`EXEC` runs every command queued since [MULTI](https://docs.hotkv.com/commands/multi/index.md), in order,
without commands from other clients in between, and returns their replies as
one array. Afterwards the connection leaves the transaction and all keys
watched with [WATCH](https://docs.hotkv.com/commands/watch/index.md) are unwatched.

The transaction does not run at all when:

- a command was refused while being queued: `EXEC` replies with
  `EXECABORT Transaction discarded because of previous errors.`;
- a watched key was changed by another client (or expired) after `WATCH`:
  `EXEC` replies with a null and nothing is run.

If a queued command fails while running (for example `INCR` on a key that does
not hold an integer), its place in the reply array holds the error and the
other commands still run. Nothing is rolled back.

Permissions are checked again for each command when `EXEC` runs; a command
that the user's ACL rules no longer allow fails with a `NOPERM` error in the
reply array.

## Return value

| Case | RESP2 | RESP3 |
| --- | --- | --- |
| The transaction ran | Array: one reply per queued command | Array |
| A watched key changed | Nil array | Null |
| A command was refused while queuing | Error `EXECABORT ...` | Error |
| No `MULTI` was sent | Error `ERR EXEC without MULTI` | Error |

## Examples

```
127.0.0.1:6379> SET name "ada"
OK
127.0.0.1:6379> MULTI
OK
127.0.0.1:6379(TX)> INCR counter
QUEUED
127.0.0.1:6379(TX)> INCR name
QUEUED
127.0.0.1:6379(TX)> EXEC
1) (integer) 1
2) (error) ERR value is not an integer or out of range
```

A transaction guarded by `WATCH`, after another client changed `balance`:

```
127.0.0.1:6379> WATCH balance
OK
127.0.0.1:6379> MULTI
OK
127.0.0.1:6379(TX)> DECRBY balance 30
QUEUED
127.0.0.1:6379(TX)> EXEC
(nil)
```

## Compatibility

Same as Redis 7 and Valkey 8.

## See also

[MULTI](https://docs.hotkv.com/commands/multi/index.md), [DISCARD](https://docs.hotkv.com/commands/discard/index.md),
[WATCH](https://docs.hotkv.com/commands/watch/index.md)