RPOPLPUSH

Apply for Redis Developer Course Redis Regular Inspection / Technical Support Redis Enterprise Server

Pop from the right of a list and push to the left

Usage: rpoplpush src_key dest_key.
The result is the same as RPOP + LPUSH, but this command is atomic.

Example: Reliable queue

Command>lpush src_key msg_1 msg_2 msg_3
Result>3
Command>lpush dest_key msg_A msg_B msg_C
Result>3
Command>rpoplpush src_key dest_key
Result>msg_1
Command>lrange src_key 0 -1
Result>0) msg_3
1) msg_2
Command>lrange dest_key 0 -1
Result>0) msg_1
1) msg_C
2) msg_B
3) msg_A

View animation



Circular list

You can set src_key and dest_key to the same key.
That makes a circular list.

Example: Circular list

Command>lpush key msg_1 msg_2 msg_3
Result>3
Command>lrange key 0 -1
Result>0) msg_3
1) msg_2
2) msg_1
Command>rpoplpush key key
Result>msg_1
Command>lrange key 0 -1
Result>0) msg_1
1) msg_3
2) msg_2

View animation



Syntax

RPOPLPUSH source destination

  • Available since version 1.2.0.
  • Time complexity is O(1).
Related commands RPOP, LPUSH
Clients for Java Jedis, Lettuce, Redisson
Clients for C Hiredis

<< LMOVE RPOPLPUSH LPUSHX >>

Email 답글이 올라오면 이메일로 알려드리겠습니다.