Redis Lists: BRPOPLPUSH
Redis BRPOPLPUSH Command
Redis BRPOPLPUSH command is used to block the connection until another client pushes to it or until a timeout is reached when source is empty. When source contains element then this command Atomically returns and removes the last element (tail) of the list stored at source, and pushes the element at the first element (head) of the list stored at the destination.
Here are some common uses and scenarios for the "BRPOPLPUSH" command:
- Task Queue Management: Transfer tasks from a primary queue to a processing queue, ensuring tasks are handled in a blocking manner.
- Workload Distribution: Distribute tasks among multiple workers by moving tasks from a work queue to a processing queue.
- Reliable Queue Pattern: Implement a reliable queue system where tasks are moved from a source list to a destination list, reducing the risk of data loss.
- Pipeline Processing: Manage data processing pipelines by moving elements through different stages represented by different lists.
Syntax:
redis 127.0.0.1:6379> BRPOPLPUSH LIST1 ANOTHER_LIST TIMEOUT
Available since
2.2.0.
Return Value
String reply, value of element stored at key or nil
Return Value Type
String
Example: Redis BRPOPLPUSH
127.0.0.1:6379> RPUSH mycolor1 R G B (integer) 3 127.0.0.1:6379> RPUSH mycolor2 Y O P (integer) 3 127.0.0.1:6379> BRPOPLPUSH mycolor1 mycolor2 100 "B" 127.0.0.1:6379> BRPOPLPUSH mycolor1 mycolor2 100 "G" 127.0.0.1:6379> BRPOPLPUSH mycolor1 mycolor2 100 "R" 127.0.0.1:6379> BRPOPLPUSH mycolor1 mycolor2 100 (nil) (100.06s)
Above example will block the client for 100 seconds to execute any command. If any data comes in the specified key lists then it will pop data and push it into another list otherwise after 100 seconds nil value is returned.
(nil) (100.06s)
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/redis/redis-brpoplpush-source-destination-timeout.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics