brpop
BRPOP
Apply for Redis Developer Course
|
Redis Regular Inspection / Technical Support
|
Redis Enterprise Server
|
|---|
Pop from the right of the list when data arrives
Usage is brpop key timeout.
If the list already has data, it is the same as RPOP. 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> | brpop key 0 |
| Result> | 0) key 1) msg_1 |
| Command> | brpop key 0 |
| Result> | 0) key 1) msg_2 (3.60s) |
When timeout is 5, wait 5 seconds for data to arrive.
Usage is brpop key 5.
Example
Client A
| Command> | lpush key msg_3 |
| Result> | 1 |
Client B
| Command> | brpop key 5 |
| Result> | 0) key 1) msg_3 (3.17s) |
| Command> | brpop key 5 |
| Result> | (nil) (5.08s) |
Multiple keys can be specified
Usage is brpop 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> | brpop key1 key2 0 |
| Result> | 0) key1 1) msg_4 |
| Command> | brpop key1 key2 0 |
| Result> | 0) key2 1) msg_5 |
Syntax
BRPOP key [key ...] timeout
- Available since version 2.0.0.
- Time complexity is O(1).
| Related commands | BLPOP, BRPOPLPUSH |
| Clients for Java | Jedis, Lettuce, Redisson | Clients for C | Hiredis |
| << BLPOP | BRPOP | BLMOVE >> |
|---|
Email
답글이 올라오면 이메일로 알려드리겠습니다.
