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 performs no operation and only 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.
Returns an error when source or destination is not of set type.
Syntax
The basic syntax of the redis Smove command is as follows:
redis 127.0.0.1:6379> SMOVE SOURCE DESTINATION MEMBER
Available Version
= 1.0.0
Return Value
Returns 1 if the member element was successfully removed. Returns 0 if the member element is not a member of the source set and no operation was 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"
Redis Set