SMOVE srckey dstkey member
Move the specified member from the set at srckey to the set at dstkey. This operation is atomic, in every given moment the element will appear to be in the source or destination set for accessing clients.
TIME COMPLEXITY: O(1)
If the source set does not exist or does not contain the specified element no operation is performed and zero is returned, otherwise the element is removed from the source set and added to the destination set. On success, one is returned, even if the element was already present in the destination set.
Note:
An error is raised if the source or destination keys contain a non-Set value.
RETURN VALUE: Integer reply, specifically:
1 if the element was moved
0 if the element was not found on the first set and no operation was performed.
Syntax:
SMOVE srckey dstkey member
Example 1: When the member is present in srcKey.
redis:6379> SADD srcKey 1000(integer) 1redis:6379> SADD srcKey 100(integer) 1redis:6379> SADD dstKey 200(integer) 1redis:6379> SMOVE srcKey dstKey 100(integer) 1
Output
1
Example 2: When the member is not present in srcKey.
redis:6379> SADD srcKey 1000(integer) 1redis:6379> SADD srcKey 100(integer) 1redis:6379> SADD dstKey 200(integer) 1redis:6379> SMOVE srcKey dstKey 2900(integer) 0
Output
0
Example 3: When srcKey or dstKey is not of type Set.
redis:6379> SADD srcKey 1000(integer) 1redis:6379> SADD srcKey 100(integer) 1redis:6379> SET redisKey 100"OK"redis:6379> SMOVE srcKey redisKey 100(error) WRONGTYPE Operation against a key holdingthe wrong kind of value
Output
(error) WRONGTYPE Operation against a key holding the wrong kind of value
No comments:
Post a Comment