Redis Set SMOVE Command
The Redis SMOVE
command moves the specified member element from the source set to the destination set.
SMOVE
operation is an atomic.
If the source set does not exist or does not contain the specified member, the command does nothing and returns 0. Otherwise, the member is removed from the source set and added to the destination set.
If the destination set already contains the member, the SMOVE
command simply removes the member from the source set without adding it to the destination set again.
If either the source or the destination is not a set, an error is returned.
Syntax
The basic syntax of the SMOVE
command is as follows:
1 | SMOVE source destination member |
Move member from the set at source to the set at destination.
Available Since
Redis version >= 1.0.0
Time Complexity
O(1)
ACL Categories
@write
, @set
, @fast
Return Value
1
if the element is moved.0
if the element is not a member of source and no operation was performed.
Example 1
Moves the specified member element from the source set to the destination set:
1 | 127.0.0.1:6379> SADD myset a b c d |
Example 2
If the source set does not exist, no operation is performed and 0 is returned.
1 | 127.0.0.1:6379> EXISTS myset2 |
Example 3
If the source set does not contain the specified element, no operation is performed and 0 is returned.
1 | 127.0.0.1:6379> SADD myset a b c d |
Example 4
When the specified element already exists in the destination set, it is only removed from the source set.
1 | 127.0.0.1:6379> SADD myset a b c d |
Example 5
An error is returned if source or destination does not hold a set value.
1 | 127.0.0.1:6379> SET dest johnson |