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"

redis之Set(无序)类型常用方法总结的更多相关文章

  1. redis之Set(有序)类型常用方法总结

    redis之Set(有序)类型常用方法总结 存--ZADD key [NX|XX] [CH] [INCR] score member [score member ...] XX: 仅仅更新存在的成员, ...

  2. redis之List类型常用方法总结

    redis之List类型常用方法总结 格式: 存---LPUSH key value [value ...] 取--LRANGE key start stop lpush key value [val ...

  3. redis之Hash类型常用方法总结

    redis之Hash类型常用方法总结 格式: 存--HMGET key field [field ...] 取--HMGET key field [field ...] M:表示能取多个值,many ...

  4. 尚硅谷redis学习4-数据类型

    redis的数据类型包括String,Hash(类似于JAVA里的map),List,Set,Zset(sorted Set) String(字符串) string是redis最基本的类型,你可以理解 ...

  5. 最全的Java操作Redis的工具类,使用StringRedisTemplate实现,封装了对Redis五种基本类型的各种操作!

    转载自:https://github.com/whvcse/RedisUtil 代码 ProtoStuffSerializerUtil.java import java.io.ByteArrayInp ...

  6. redis数据类型-散列类型

    Redis数据类型 散列类型 Redis是采用字典结构以键值对的形式存储数据的,而散列类型(hash)的键值也是一种字典结构,其存储了字段(field)和字段值的映射,但字段值只能是字符串,不支持其他 ...

  7. 7、Redis中对ZSet类型的操作命令

    写在前面的话:读书破万卷,编码如有神 --------------------------------------------------------------------   ---------- ...

  8. 6、Redis中对Hash类型的操作命令

    写在前面的话:读书破万卷,编码如有神 -------------------------------------------------------------------- ------------ ...

  9. 5、Redis中对Set类型的操作命令

    写在前面的话:读书破万卷,编码如有神 -------------------------------------------------------------------- ------------ ...

随机推荐

  1. R语言 plot()函数

    语法: plot(x, y, ...) x,y分别是两个向量,x为横轴坐标,y为纵轴坐标 其他参数: type= "p" for points, 散点图 默认 "l&qu ...

  2. java linux安装jdk,git, maven

    jdk8下载地址:https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html mkdir ...

  3. 「CF891C」Envy

    传送门 Luogu 解题思路 考虑最小生成树的几个性质: 所有最小生成树中边权相等的边的条数相等 在任意一颗最小生成树中,边权相等的边所联通的点集一定 那么我们考虑把边权相等的边单独拿出来考虑. 每次 ...

  4. Java入门笔记 04-异常处理

    一. 异常概述: 1. 异常体系结构图: java.lang.Throwable          |-----java.lang.Error:一般不编写针对性的代码进行处理.          |- ...

  5. 802.1X与Cisco基于身份的网络服务(IBNS)

    Cisco基于身份的网络服务(Identity-Based Networking Services,IBNS)是一种以IEEE802.1X标准为基础的安全架构,具有认证.用户策略.访问控制等多种功能, ...

  6. Java面向对象编程 -4

    声明static属性 static 是一个关键字,这个关键字主要是用来定义属性和方法. static内存分析 在正常开发之中每一个对象都要保存有各自的属性 所以此时程序没有问题 但是如果country ...

  7. 的aspnet_client文件夹

    在早期,有一些asp.net组件是默认要调用(从客户端调用)服务器根(域名)下这个子目录里边的文件的. 不过如果你使用高版本的asp.net,那么全都从你的网站里调用了,因为asp.net有了更好地直 ...

  8. jmeter download historyList

    https://archive.apache.org/dist/jmeter/binaries/ 反馈,问题和评论应发送到Apache JMeter Users 邮件列表. 有关更多信息, 请访问Ap ...

  9. arcPy实现要素图层数据的复制(选择特定字段填写属性)

    >>> import arcpy>>> fc=r"D:\楚雄州数据\testdata.gdb">>> editor=arcpy ...

  10. centos 默认php 版本太低移到高版本的办法

    // centos 默认有php 版本太低转移到高版本的解决办法 php -v 版本低 ln -s /usr/local/php/bin/php /usr/bin/php