brpoplpush
BRPOPLPUSH
When data arrives, pop from the right of the list and push to the left.
Usage is brpoplpush src_key dest_key timeout.
The result is the same as rpop + lpush. This command is atomic.
If the list already has data, it is the same as RPOPLPUSH. 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 data and elapsed time (seconds).
Example: Reliable queue
Client A
| Command> | lpush scr_key msg_1
|
| Result> | 1
|
|
|
|
|
|
|
| Command> | lpush scr_key msg_2
|
| Result> | 1
|
|
|
|
|
Client B
|
|
|
|
| Command> | brpoplpush src_key dest_key 0
|
| Result> | msg_1 |
| Command> | brpoplpush src_key dest_key 0
|
|
|
|
|
| Result> | msg_2
(4.30s) |
View animation
Specify timeout
Usage is brpoplpush src_key dest_key timeout.
Example: Reliable queue
Client A
| Command> | lpush src_key msg_1
|
| Result> | 1
|
|
|
|
|
|
|
|
|
|
|
|
|
Client B
|
|
|
|
| Command> | brpoplpush src_key dest_key 5
|
| Result> | msg_1 |
| Command> | brpoplpush src_key dest_key 5
|
| After 5 seconds
|
| Result> | (nil)
(5.03s)
|
View animation
Syntax
BRPOPLPUSH source destination timeout
- Available since version 2.2.0.
- Time complexity is O(1).