SMOVE

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

Move a member from the source set to the destination set

Usage is smove source_key destination_key member.
The member is removed from the source set.

Example

Command>sadd src_key A B C
Result>3
Command>sadd dest_key D
Result>1
Command>smove src_key dest_key A
Result>1
Command>smembers src_key
Result> 1) B
2) C   A was removed from the source set
Command>smembers dest_key
Result> 1) A   A was added to the destination set
2) D
Note SMOVE is processed atomically.


If the destination set does not exist, it is created and the member is added

Example

Command>del dest_key   delete the destination set
Result>1
Command>smove src_key dest_key B
Result>1
Command>smembers src_key
Result> 1) C
Command>smembers dest_key    the destination set was created and member B was added
Result> 1) B


If you specify a member that is not in the source set

Or if the source set itself does not exist, nothing happens and 0 is returned.

Example

Command>smove src_key dest_key X
Result>0
Command>smove xxx_key dest_key X
Result>0

View animation



Syntax

SMOVE source_key destination_key member

  • Available since version 1.0.0.
  • Time complexity is O(1).
Related commands SPOP, SREM
Clients for Java Jedis, Lettuce, Redisson
Clients for C Hiredis

<< SMISMEMBER SMOVE SPOP >>

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