redis之Set(无序)类型常用方法总结

redis之Set(无序)类型常用方法总结

存--sadd key member [member ...]
取--SMEMBERS key
  1. sadd key member [member ...] 向集合添加一个或多个成员

    127.0.0.1:6379> sadd lt zhangsan lishi wangwu
    (integer) 3
    127.0.0.1:6379> smembers lt
    1) "wangwu"
    2) "lishi"
    3) "zhangsan"
    
  2. smembers key 获取一个key对应的集合元素

    127.0.0.1:6379> sadd lt zhangsan lishi wangwu
    (integer) 3
    127.0.0.1:6379> smembers lt
    1) "wangwu"
    2) "lishi"
    3) "zhangsan"
    
  3. scard key 获取集合的成员数

    127.0.0.1:6379> sadd lt zhangsan lishi wangwu
    (integer) 3
    127.0.0.1:6379> smembers lt
    1) "wangwu"
    2) "lishi"
    3) "zhangsan"
    127.0.0.1:6379> scard lt
    (integer) 3
    
  4. sdiff key1 [key2] 返回给定所有集合的差集

    127.0.0.1:6379> sadd lt zhangsan lishi wangwu
    (integer) 3
    127.0.0.1:6379> smembers lt
    1) "wangwu"
    2) "lishi"
    3) "zhangsan"
    127.0.0.1:6379> scard lt
    (integer) 3
    127.0.0.1:6379> sadd plf lishi wangwu jia yi
    (integer) 4
    127.0.0.1:6379> SDIFF plf lt
    1) "yi"
    2) "jia"
    127.0.0.1:6379> SDIFF lt plf
    1) "zhangsan"
    
  5. SDIFFSTORE destination key1 [key2] 返回给定所有集合的差集并存储在 destination 中

    redis 127.0.0.1:6379> SADD myset "hello"
    (integer) 1
    redis 127.0.0.1:6379> SADD myset "foo"
    (integer) 1
    redis 127.0.0.1:6379> SADD myset "bar"
    (integer) 1
    redis 127.0.0.1:6379> SADD myset2 "hello"
    (integer) 1
    redis 127.0.0.1:6379> SADD myset2 "world"
    (integer) 1
    redis 127.0.0.1:6379> SDIFFSTORE destset myset myset2
    (integer) 2
    redis 127.0.0.1:6379> SMEMBERS destset
    1) "foo"
    2) "bar"
    
  6. SINTER key1 [key2] 返回给定所有集合的交集

    127.0.0.1:6379> sadd lt zhangsan lishi wangwu
    (integer) 3
    127.0.0.1:6379> sadd plf lishi wangwu jia yi
    (integer) 4
    127.0.0.1:6379> sinter plf lt
    1) "wangwu"
    2) "lishi"
    
  7. SINTERSTORE destination key1 [key2] 返回给定所有集合的交集并存储在 destination 中

    redis 127.0.0.1:6379> SADD myset1 "hello"
    (integer) 1
    redis 127.0.0.1:6379> SADD myset1 "foo"
    (integer) 1
    redis 127.0.0.1:6379> SADD myset1 "bar"
    (integer) 1
    redis 127.0.0.1:6379> SADD myset2 "hello"
    (integer) 1
    redis 127.0.0.1:6379> SADD myset2 "world"
    (integer) 1
    redis 127.0.0.1:6379> SINTERSTORE myset myset1 myset2
    (integer) 1
    redis 127.0.0.1:6379> SMEMBERS myset
    1) "hello"
    
  8. SISMEMBER key member 判断 member 元素是否是集合 key 的成员

    redis 127.0.0.1:6379> SADD myset1 "hello"
    (integer) 1
    redis 127.0.0.1:6379> SISMEMBER myset1 "hello"
    (integer) 1
    redis 127.0.0.1:6379> SISMEMBER myset1 "world"
    (integer) 0
    
  9. SMEMBERS key 返回集合中的所有成员

    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> SMEMBERS myset1
    1) "World"
    2) "Hello"
    
  10. SMOVE source destination member 将 member 元素从 source 集合移动到 destination 集合

    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"
    
  11. SPOP key 移除并返回集合中的一个随机元素

    redis> SADD myset "one"
    (integer) 1
    redis> SADD myset "two"
    (integer) 1
    redis> SADD myset "three"
    (integer) 1
    redis> SPOP myset
    "one"
    redis> SMEMBERS myset
    1) "three"
    2) "two"
    redis> SADD myset "four"
    (integer) 1
    redis> SADD myset "five"
    (integer) 1
    redis> SPOP myset 3
    1) "five"
    2) "four"
    3) "two"
    redis> SMEMBERS myset
    1) "three"
    redis> 
    
  12. SRANDMEMBER key [count] 返回集合中一个或多个随机数

    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> SRANDMEMBER myset1
    "bar"
    redis 127.0.0.1:6379> SRANDMEMBER myset1 2
    1) "Hello"
    2) "world"
    
  13. SREM key member1 [member2] 移除集合中一个或多个成员

    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> SREM myset1 "hello"
    (integer) 1
    redis 127.0.0.1:6379> SREM myset1 "foo"
    (integer) 0
    redis 127.0.0.1:6379> SMEMBERS myset1
    1) "bar"
    2) "world"
    
  14. SUNION key1 [key2] 返回所有给定集合的并集

    redis> SADD key1 "a"
    (integer) 1
    redis> SADD key1 "b"
    (integer) 1
    redis> SADD key1 "c"
    (integer) 1
    redis> SADD key2 "c"
    (integer) 1
    redis> SADD key2 "d"
    (integer) 1
    redis> SADD key2 "e"
    (integer) 1
    redis> SUNION key1 key2
    1) "a"
    2) "c"
    3) "b"
    4) "e"
    5) "d"
    redis> 
    
  15. SUNIONSTORE destination key1 [key2]所有给定集合的并集存储在 destination 集合中

    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 "hello"
    (integer) 1
    redis 127.0.0.1:6379> SADD myset2 "bar"
    (integer) 1
    redis 127.0.0.1:6379> SUNIONSTORE myset myset1 myset2
    (integer) 1
    redis 127.0.0.1:6379> SMEMBERS myset
    1) "bar"
    2) "world"
    3) "hello"
    4) "foo"
    
  16. SSCAN key cursor [MATCH pattern] [COUNT count] 迭代集合中的元素

    redis 127.0.0.1:6379> SADD myset1 "hello"
    (integer) 1
    redis 127.0.0.1:6379> SADD myset1 "hi"
    (integer) 1
    redis 127.0.0.1:6379> SADD myset1 "bar"
    (integer) 1
    redis 127.0.0.1:6379> sscan myset1 0 match h*
    1) "0"
    2) 1) "hello"
       2) "h1"
    
posted @ 2019-06-25 00:00  Hello_Jack  阅读(229)  评论(0编辑  收藏  举报
# 页脚html代码 /*头部导航栏*/ #navigator { font-size:15px; border-bottom: 1px solid #ededed; border-top: 1px solid #ededed; height: 60px;/*导航栏高度,原始50*/ clear: both; margin-top: 25px; } /*导航栏设置,可以自定义导航栏的目录*/ #navList { min-height: 35px; float: left; } #navList li { /*每一个栏目节点*/ float: left; margin: 0 5px 0 0; /*这里原来是0 40px 0 0 */ } #navList a { /*栏目文字的格式*/ display: block; width: 5em; height: 22px; float: left; text-align: center; padding-top: 19px; }