WAIT
WAIT numreplicas timeout
- Group
- Server
- Complexity
- O(1)
- Arity
- 3 (exactly, counting the command name)
- Flags
- blocking
- 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 or a script, WAIT replies at once
with the current count.
Options
Section titled “Options”| Argument | Meaning |
|---|---|
numreplicas |
How many replicas must acknowledge. |
timeout |
Milliseconds to wait at most. 0 waits as long as it takes. |
Return value
Section titled “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
Section titled “Examples”127.0.0.1:6379> SET order:1001 "paid"OK127.0.0.1:6379> WAIT 1 500(integer) 1127.0.0.1:6379> WAIT 3 500(integer) 2Compatibility
Section titled “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
Section titled “See also”WAITAOF, ROLE,
INFO (replication), replication
In a cluster: Replicas and failover
Was this page helpful?
Thanks for the feedback.