# WAIT

> Block until this connection's writes have reached a number of replicas, or a timeout passes.

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

```
WAIT numreplicas timeout
```

- Group: Server
- Complexity: O(1)
- HotKV Cloud: all plans
- On-Premise: no license needed

Replication is asynchronous: a write is acknowledged to the client before
replicas have it. `WAIT` lets a client that needs more certainty wait until
at least `numreplicas` replicas have acknowledged every write this
connection made so far. It returns as soon as that happens, or when
`timeout` milliseconds pass, and replies with the number of replicas that
have the writes either way.

`WAIT` reduces the window for losing a write when the primary fails, but it
does not make replication synchronous: a write that times out is not undone.

The connection is blocked while it waits; other clients are served as
usual. Inside [MULTI](https://docs.hotkv.com/commands/multi/index.md) or a script, `WAIT` replies at once
with the current count.

## Options

| Argument | Meaning |
| --- | --- |
| `numreplicas` | How many replicas must acknowledge. |
| `timeout` | Milliseconds to wait at most. `0` waits as long as it takes. |

## Return value

| Case | Reply (RESP2 and RESP3) |
| --- | --- |
| On a primary | Integer: replicas that acknowledged this connection's writes |
| On a replica | Integer `0`, at once |
| `numreplicas` is not an integer | Error `ERR value is not an integer or out of range` |
| `timeout` is not an integer | Error `ERR timeout is not an integer or out of range` |
| `timeout` is negative | Error `ERR timeout is negative` |

## Examples

```
127.0.0.1:6379> SET order:1001 "paid"
OK
127.0.0.1:6379> WAIT 1 500
(integer) 1
127.0.0.1:6379> WAIT 3 500
(integer) 2
```

## Compatibility

Same arguments and replies as Redis 7 and Valkey 8 on a primary. On a
replica, Redis replies with an error; HotKV replies `0`.

## See also

[WAITAOF](https://docs.hotkv.com/commands/waitaof/index.md), [ROLE](https://docs.hotkv.com/commands/role/index.md),
[INFO](https://docs.hotkv.com/commands/info/index.md) (`replication`), [replication](https://docs.hotkv.com/operate/replication/index.md)

In a cluster: [Replicas and failover](https://docs.hotkv.com/clustering/replicas-and-failover/index.md#where-writes-can-be-lost)