RPOPLPUSH command in redis

RPOPLPUSH srckey dstkey

Atomically return and remove the last (tail) element of the srckey list, and push the element as the first (head) element of the dstkey list.

For example if the source list contains the elements "a","b","c" and the destination list contains the elements "foo","bar" after an RPOPLPUSH command the content of the two lists will be "a","b" and "c","foo","bar".

TIME COMPLEXITY: O(1)

Note

1. If the key does not exist or the list is already empty the special value 'nil' is returned. 

2. If the srckey and dstkey are the same the operation is equivalent to removing the last element from the list and pushing it as the first element of the list, so it's a "list rotation" command.

RETURN VALUE: Bulk reply.

Syntax:

RPOPLPUSH srckey dstkey

Example 1: When the srckey is present.

redis:6379> LPUSH myList 200
(integer) 1
redis:6379> LPUSH myList 300
(integer) 2
redis:6379> RPOPLPUSH myList myList2
"200"

Output

200


Example 2: When the srckey is not present

redis:6379> RPOPLPUSH myList12 redisKey12
(nil)

Output

nil


No comments:

Post a Comment