Redis Smove Command
The Redis Smove command moves the specified member element from the source set to the destination set.
SMOVE is an atomic operation.
If the source set does not exist or does not contain the specified member element, the SMOVE command does not perform any operation and returns 0. Otherwise, the member element is removed from the source set and added to the destination set.
When the destination set already contains the member element, the SMOVE command simply deletes the member element from the source set.
An error is returned if the source or destination is not a set type.
Syntax
The basic syntax for the redis Smove command is as follows:
redis 127.0.0.1:6379> SMOVE SOURCE DESTINATION MEMBER
Available Versions
= 1.0.0
Return Value
Returns 1 if the member element is successfully removed. Returns 0 if the member element is not a member of the source set and no operation is performed on the destination set.
Example
redis 127.0.0.1:6379> SADD myset1 "hello"
(integer) 1
redis 127.0.0.1:6379> SADD myset1 "world"
(integer) 1
redis 127.0.0.1:6379> SADD myset1 "bar"
(integer) 1
redis 127.0.0.1:6379> SADD myset2 "foo"
(integer) 1
redis 127.0.0.1:6379> SMOVE myset1 myset2 "bar"
(integer) 1
redis 127.0.0.1:6379> SMEMBERS myset1
1) "World"
2) "Hello"
redis 127.0.0.1:6379> SMEMBERS myset2
1) "foo"
2) "bar"