blpop
BLPOP
Apply for Redis Developer Course
|
Redis Regular Inspection / Technical Support
|
Redis Enterprise Server
|
|---|
Pop from the left of the list when data arrives
Usage is blpop key timeout.
If the list already has data, it is the same as LPOP. If there is no data, it waits for timeout (seconds).
When timeout is 0, it waits until data is entered. When data arrives it pops and shows key, data, and elapsed time (seconds).
Example
Client A
| Command> | lpush key msg_1 |
| Result> | 1 |
| Command> | lpush key msg_2 |
| Result> | 1 |
Client B
| Command> | blpop key 0 |
| Result> | 0) key 1) msg_1 |
| Command> | blpop key 0 |
| Result> | 0) key 1) msg_2 (3.60s) |
When timeout is 5, wait 5 seconds for data to arrive.
Usage is blpop key 5.
Example
Client A
| Command> | lpush key msg_3 |
| Result> | 1 |
Client B
| Command> | blpop key 5 |
| Result> | 0) key 1) msg_3 (3.17s) |
| Command> | blpop key 5 |
| Result> | (nil) (5.08s) |
Multiple keys can be specified
Usage is blpop key1 key2 timeout.
It checks the lists in the specified order and, if data is found, takes one item and then ends.
Specifying multiple keys does not mean it returns multiple items.
Example
Client A
| Command> | lpush key1 msg_4 |
| Result> | 1 |
| Command> | lpush key2 msg_5 |
| Result> | 1 |
Client B
| Command> | blpop key1 key2 0 |
| Result> | 0) key1 1) msg_4 |
| Command> | blpop key1 key2 0 |
| Result> | 0) key2 1) msg_5 |
Syntax
BLPOP key [key ...] timeout
- Available since version 2.0.0.
- Time complexity is O(1).
| Related commands | BRPOP, BRPOPLPUSH |
| Clients for Java | Jedis, Lettuce, Redisson | Clients for C | Hiredis |
| << RPUSHX | BLPOP | BRPOP >> |
|---|
Email
답글이 올라오면 이메일로 알려드리겠습니다.
