w3resource

Redis Sets: SMOVE

SMOVE source destination member

Redis SMOVE command is used to move a member from one set to another set. If the source set does not exist or does not contain the specified element, no operation is performed and 0 is returned. Otherwise, the element is removed from the source set and added to the destination set. When the specified element already exists in the destination set, it is only removed from the source set. An error is returned if source or destination does not hold a set value.

Syntax:

SMOVE SOURCE DESTINATION MEMBER 

Available since:

1.0.0.

Return Value:

Integer reply,

  • 1 if the element is moved.
  • 0 if the element is not a member of the source and no operation was performed.

Return Value Type:

Integer

Example: Redis SMOVE

127.0.0.1:6379> SADD source_key 1 2 3
(integer) 3
127.0.0.1:6379> SADD dest_key 4
(integer) 1
127.0.0.1:6379> SMOVE source_key dest_key 1
(integer) 1
127.0.0.1:6379> SMEMBERS source_key
1) "2"
2) "3"
127.0.0.1:6379> SMEMBERS dest_key
1) "1"
2) "4"

If you do not add the member to create and set objectives

127.0.0.1:6379> DEL dest_key
(integer) 1
127.0.0.1:6379> SMOVE source_key dest_key 2
(integer) 1
127.0.0.1:6379> SMEMBERS source_key
1) "3"
127.0.0.1:6379> SMEMBERS dest_key
1) "2"

If you do not specify a member set in sources

If the source or set its own, but nothing happened, it returns zero.

127.0.0.1:6379> SMOVE source_key dest_key 9
(integer) 0
127.0.0.1:6379> SMOVE sources_key dest_key 9
(integer) 0


Follow us on Facebook and Twitter for latest update.