- 用法
-
SMOVE source destination member
- 复杂度
- O(1)
- 起始版本
- 1.0.0
- ACL 类别
- @set, @write, @fast
将 member
从 source
集合移动到 destination
集合。此操作是原子的。在任何给定时刻,对于其他客户端而言,该元素都将是 source
或 destination
的成员。
如果源集合不存在或不包含指定元素,则不执行任何操作并返回 0
。否则,该元素将从源集合中移除并添加到目标集合中。当指定元素已存在于目标集合中时,它只会从源集合中移除。
如果 source
或 destination
不包含集合值,则返回错误。
示例
127.0.0.1:6379> SADD myset "one"
(integer) 1
127.0.0.1:6379> SADD myset "two"
(integer) 1
127.0.0.1:6379> SADD myotherset "three"
(integer) 1
127.0.0.1:6379> SMOVE myset myotherset "two"
(integer) 1
127.0.0.1:6379> SMEMBERS myset
1) "one"
127.0.0.1:6379> SMEMBERS myotherset
1) "three"
2) "two"
RESP2/RESP3 回复
以下之一