w3resource

Redis Lists: RPOPLPUSH

Redis RPOPLPUSH Command

Redis RPOPLPUSH command is used to return and remove the last element of the list stored at the source, and pushes the element at the first element of the list stored at the destination.

Here are some common uses and scenarios for the "RPOPLPUSH" command:

  • Task Queue Management: Move tasks from a processing queue to a completed tasks list.
  • Workload Distribution: Distribute tasks among multiple workers by moving tasks from one list to another.
  • Pipeline Processing: Implement data processing pipelines where elements are moved between different stages represented by lists.
  • Data Integrity: Ensure reliable data handling by moving elements atomically between lists.
  • Timeout Handling: Specify a timeout to limit how long the command will block, allowing for flexible processing strategies.

Syntax:

RPOPLPUSH SOURCE_KEY_NAME DESTINATION_KEY_NAME

Available since

1.2.0.

Return Value

String reply, the element being popped and pushed.

Return Value Type

String

Example: Redis RPOPLPUSH: data in a list put right on the left.

127.0.0.1:6379> LPUSH mycolor1 white black red blue
(integer) 4
127.0.0.1:6379> LPUSH mycolor2 GREEN ORANGE YELLOW PINK
(integer) 4
127.0.0.1:6379> RPOPLPUSH mycolor1 mycolor2
"white"
127.0.0.1:6379> LRANGE mycolor1 0 -1
1) "blue"
2) "red"
3) "black"
127.0.0.1:6379> LRANGE mycolor2 0 -1
1) "white"
2) "PINK"
3) "YELLOW"
4) "ORANGE"
5) "GREEN"

Example: Redis RPOPLPUSH: Circular list

127.0.0.1:6379> LPUSH mycolor1 white black red blue
(integer) 4
127.0.0.1:6379> LRANGE mycolor1 0 -1
1) "blue"
2) "red"
3) "black"
4) "white"
127.0.0.1:6379> RPOPLPUSH mycolor1 mycolor1
"white"
127.0.0.1:6379> LRANGE mycolor1 0 -1
1) "white"
2) "blue"
3) "red"
4) "black"

Previous: RPOP
Next: RPUSH



Become a Patron!

Follow us on Facebook and Twitter for latest update.

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://w3resource.com/redis/redis-rpoplpush-source-destination.php