Redis – List Rpoplpush Command

  • Post author:
  • Post category:Redis
  • Post comments:0 Comments

Redis RPOPLPUSH command returns and removes the last element (tail) of the list stored at the source, and pushes the element at the first element (head) of the list stored at the destination.

Return Value

String reply, the element being popped and pushed.

Syntax

Following is the basic syntax of Redis RPOPLPUSH command.

redis 127.0.0.1:6379> RPOPLPUSH SOURCE_KEY_NAME DESTINATION_KEY_NAME

Example

redis 127.0.0.1:6379> RPUSH mylist "hello" 
(integer) 1 
redis 127.0.0.1:6379> RPUSH mylist "foo" 
(integer) 2 
redis 127.0.0.1:6379> RPUSH mylist "bar" 
(integer) 3 
redis 127.0.0.1:6379> RPOPLPUSH mylist myotherlist 
"bar" 
redis 127.0.0.1:6379> LRANGE mylist 0 -1 
1) "hello" 
2) "foo" 

Leave a Reply