Redis Keys: WAIT
WAIT numslaves timeout
The Redis WAIT command blocks the current client until all the previous write commands are successfully transferred and acknowledged by at least the specified number of slaves. If the timeout, specified in milliseconds, is reached, the command returns even if the specified number of slaves were not yet reached.
The command will always return the number of slaves that acknowledged the write commands sent before the WAIT command, both in the case where the specified number of slaves are reached, or when the timeout is reached.
A few remarks:
- When WAIT returns, all the previous write commands sent in the context of the current connection are guaranteed to be received by the number of slaves returned by WAIT.
- If the command is sent as part of a MULTI transaction, the command does not block but instead just return ASAP the number of slaves that acknowledged the previous write commands.
- A timeout of 0 means to block forever.
- Since WAIT returns the number of slaves reached both in the case of failure and success, the client should check that the returned value is equal or greater to the replication level it demanded.
In the specific case of the implementation of WAIT, Redis remembers, for each client, the replication offset of the produced replication stream when a given write command was executed in the context of a given client. When WAIT is called Redis checks if the specified number of slaves already acknowledged this offset or a greater one.
WAIT numslaves timeout
Integer reply: The command returns the number of slaves reached by all the writes performed in the context of the current connection.
Return Value Type
Example: Redis WAIT
First, create some keys in redis and set some values in it.
127.0.0.1:6379> SET key1 Apple OK 127.0.0.1:6379> WAIT 2 1 (integer) 0 127.0.0.1:6379> WAIT 2 1000 (integer) 0 (1.01s)
In the above example, the first call to WAIT does not use a timeout and asks for the write to reach 1 slave. It returns with success. In the second attempt instead, we put a timeout and ask for the replication of the write to two slaves. Since there is a single slave available, after one-second WAIT unblocks and returns 1, the number of slaves reached.
- Weekly Trends
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
- Python Tutorial
- Python Array Exercises
- SQL Cross Join
- C# Sharp Array Exercises