Set(集合)
set的值是不可重复的!
127.0.0.1:6379> SADD myset "lixin,hello" #set集合中添加匀速
(integer) 1
127.0.0.1:6379> SADD myset "lilin,hello"
(integer) 1
127.0.0.1:6379> SMEMBERS myset #查看指定set的所有值
1) "lixin,hello"
2) "lilin,hello"
127.0.0.1:6379> SISMEMBER myset lixin,hello #判断某一个值是不是在set集合中!
(integer) 1
127.0.0.1:6379> SISMEMBER myset lilin,hello
(integer) 1
127.0.0.1:6379> scard myset #获取set集合中的内容元素个数
(integer) 2
127.0.0.1:6379> SADD myset "hello"
(integer) 1
127.0.0.1:6379> SADD myset "world"
(integer) 1
127.0.0.1:6379> scard myset
(integer) 4
127.0.0.1:6379>
REM : 移动set集合中的指定元素
127.0.0.1:6379> SREM myset hello
(integer) 1
127.0.0.1:6379> scard myset
(integer) 3
127.0.0.1:6379> SMEMBERS myset
1) "lixin,hello"
2) "world"
3) "lilin,hello"
127.0.0.1:6379>
Set无序不重复集合,抽随机
127.0.0.1:6379> SRANDMEMBER myset
"lixin,hello"
127.0.0.1:6379> SRANDMEMBER myset
"lilin,hello"
127.0.0.1:6379> SRANDMEMBER myset
"lilin,hello"
127.0.0.1:6379>
127.0.0.1:6379> SRANDMEMBER myset
"lixin,hello"
127.0.0.1:6379> SRANDMEMBER myset
"world"
127.0.0.1:6379> SMEMBERS myset
1) "lixin,hello"
2) "world"
3) "lilin,hello"
127.0.0.1:6379> spop myset #随机删除一些set集合中的元素!
"lilin,hello"
127.0.0.1:6379> spop myset
"world"
127.0.0.1:6379> SMEMBERS myset
1) "lixin,hello"
127.0.0.1:6379>
127.0.0.1:6379> SADD myset "a"
(integer) 1
127.0.0.1:6379> SADD myset "b"
(integer) 1
127.0.0.1:6379> SADD myset "c"
(integer) 1
127.0.0.1:6379> SADD myset "e"
(integer) 1
127.0.0.1:6379> SADD myset2 "e"
(integer) 1
127.0.0.1:6379> smove myset myset2 "a" #将一个指定的值,移动到另一个set集合!
(integer) 1
127.0.0.1:6379> SMEMBERS mysetw
(empty array)
127.0.0.1:6379> SMEMBERS myset2
1) "a"
2) "e"
127.0.0.1:6379> SMEMBERS myset
1) "c"
2) "b"
3) "e"
127.0.0.1:6379>
- 微博,B站,共同关注
- 数字集合类:
- 交集 SUNION
- 并集 SINTER
- 差集 SDIFF
127.0.0.1:6379> SMEMBERS myset
1) "c"
2) "b"
3) "e"
127.0.0.1:6379> SADD myset3 "e"
(integer) 1
127.0.0.1:6379> SADD myset3 "f"
(integer) 1
127.0.0.1:6379> SADD myset3 "g"
(integer) 1
127.0.0.1:6379> SDIFF myset myset3
1) "b"
2) "c"
127.0.0.1:6379> sinter myset myset3
1) "e"
127.0.0.1:6379>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。