# WAITAOF

> Block until this connection's writes are in the append-only file on disk, locally and on replicas.

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

```
WAITAOF numlocal numreplicas timeout
```

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

`WAITAOF` waits until every write this connection made so far is in an
append-only file (AOF) on disk: on this server when `numlocal` is `1`, and
on at least `numreplicas` replicas. It returns as soon as both are true, or
when `timeout` milliseconds pass, and reports how far it got either way.

When the AOF reaches the disk depends on `appendfsync`: at once with
`always`, within about a second with `everysec`, and only at the next
rewrite with `no`. Each replica follows its own `appendfsync`. With `everysec`, a short `timeout` can run out
before the fsync, so give it a second or more.

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, `WAITAOF` replies at
once with the current state.

## Options

| Argument | Meaning |
| --- | --- |
| `numlocal` | `1` to wait for this server's AOF, `0` not to. Needs `appendonly yes` when `1`. |
| `numreplicas` | How many replicas must have the writes in their AOF on disk. |
| `timeout` | Milliseconds to wait at most. `0` waits as long as it takes. |

## Return value

An array of two integers, in RESP2 and RESP3:

1. `1` if this server's AOF on disk has the writes, else `0` (always `0`
   with the AOF off).
2. The number of replicas whose AOF on disk has them.

| Error case | Error |
| --- | --- |
| `numlocal` not an integer | `ERR value is not an integer or out of range` |
| `numlocal` not 0 or 1 | `ERR value is out of range, value must between 0 and 1` |
| `numreplicas` not a non-negative integer | `ERR value is out of range, must be positive` |
| `timeout` not an integer | `ERR timeout is not an integer or out of range` |
| `timeout` negative | `ERR timeout is negative` |
| Sent to a replica | `ERR WAITAOF cannot be used with replica instances. Please also note that writes to replicas are just local and are not propagated.` |
| `numlocal` 1 with the AOF off | `ERR WAITAOF cannot be used when numlocal is set but appendonly is disabled.` |

## Examples

```
127.0.0.1:6379> SET invoice:77 "issued"
OK
127.0.0.1:6379> WAITAOF 1 1 1000
1) (integer) 1
2) (integer) 1
```

## Compatibility

Same arguments, replies and errors as Redis 7.2 and later, and Valkey 8.

## See also

[WAIT](https://docs.hotkv.com/commands/wait/index.md), [BGREWRITEAOF](https://docs.hotkv.com/commands/bgrewriteaof/index.md),
[persistence](https://docs.hotkv.com/persistence/index.md)

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