w3resource

Redis Lists: RPOPLPUSH

RPOPLPUSH source destination

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.

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



Follow us on Facebook and Twitter for latest update.