redis之Set(无序)类型常用方法总结
redis之Set(无序)类型常用方法总结
存--sadd key member [member ...]
取--SMEMBERS key
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"
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"
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
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"
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"
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"
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"
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
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"
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"
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>
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"
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"
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>
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"
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(无序)类型常用方法总结的更多相关文章
- redis之Set(有序)类型常用方法总结
redis之Set(有序)类型常用方法总结 存--ZADD key [NX|XX] [CH] [INCR] score member [score member ...] XX: 仅仅更新存在的成员, ...
- redis之List类型常用方法总结
redis之List类型常用方法总结 格式: 存---LPUSH key value [value ...] 取--LRANGE key start stop lpush key value [val ...
- redis之Hash类型常用方法总结
redis之Hash类型常用方法总结 格式: 存--HMGET key field [field ...] 取--HMGET key field [field ...] M:表示能取多个值,many ...
- 尚硅谷redis学习4-数据类型
redis的数据类型包括String,Hash(类似于JAVA里的map),List,Set,Zset(sorted Set) String(字符串) string是redis最基本的类型,你可以理解 ...
- 最全的Java操作Redis的工具类,使用StringRedisTemplate实现,封装了对Redis五种基本类型的各种操作!
转载自:https://github.com/whvcse/RedisUtil 代码 ProtoStuffSerializerUtil.java import java.io.ByteArrayInp ...
- redis数据类型-散列类型
Redis数据类型 散列类型 Redis是采用字典结构以键值对的形式存储数据的,而散列类型(hash)的键值也是一种字典结构,其存储了字段(field)和字段值的映射,但字段值只能是字符串,不支持其他 ...
- 7、Redis中对ZSet类型的操作命令
写在前面的话:读书破万卷,编码如有神 -------------------------------------------------------------------- ---------- ...
- 6、Redis中对Hash类型的操作命令
写在前面的话:读书破万卷,编码如有神 -------------------------------------------------------------------- ------------ ...
- 5、Redis中对Set类型的操作命令
写在前面的话:读书破万卷,编码如有神 -------------------------------------------------------------------- ------------ ...
随机推荐
- 7,请描述下cookies,sessionStorage和localStorage的区别
7,请描述下cookies,sessionStorage和localStorage的区别 首先,cookie是网站为了标识用户身份而储存在用户本地终端(client side,百科: 本地终端指与计算 ...
- VS2017项目中使用代码连接MySQL数据库,以及进行数据添加
//头文件 #include "mysql.h" //函数定义 // 执行sql语句, 包括增加.删除.更新数据 bool ExecuteSql(MYSQL m_mysql,con ...
- 计算机二级-C语言-字符数字转化为整型数字。形参与实参类型相一致。double类型的使用。
//函数fun功能:将a和b所指的两个字符串分别转化成面值相同的整数,并进行相加作为函数值返回,规定只含有9个以下数字字符. //重难点:字符数字转化为整型数字. #include <stdio ...
- NAT穿透的详细讲解及分析
原文地址:http://bbs.pediy.com/thread-131961.htm 一.什么是NAT?为什么要使用NAT?NAT是将私有地址转换为合法IP地址的技术,通俗的讲就是将内网与内网通信时 ...
- Vue-footer始终置底
需求:当页面高度不足一屏时需要footer固定显示在页面底部,而页面内容超过一屏时需要footer紧跟在页面内容的最后. 思路:通过获取 网页可见区域高度:document.body.clientHe ...
- C++ STL之集合set的使⽤
写在最前面,本文摘录于柳生笔记: set是集合,一个set里面个元素各不相同的,而且set会按照元素从小到大的进行排序,一下是set的常用方法:
- 21. Regular Expressions--from Apache
转自: http://jmeter.apache.org/usermanual/regular_expressions.html 21.1 Overview¶ JMeter includes the ...
- kafka中常用API的简单JAVA代码
通过之前<kafka分布式消息队列介绍以及集群安装>的介绍,对kafka有了初步的了解.本文主要讲述java代码中常用的操作. 准备:增加kafka依赖 <dependency> ...
- 指令——mdadm
Mdadm命令详解 Linux内核中有一个md(multiple devices)模块在底层管理RAID设备,它会在应用层给我们提供一个应用程序的工具mdadm ,mdadm是linux下用于创建和管 ...
- layer 当前页获取iframe页的DOM元素
layer.layui 开启iframe 之后,获取iframe 内容做自定义处理. parent.layer.open({ type: , title: '任務執行狀況.', shadeClose ...