当前位置:网站首页>Redis:集合Set类型数据的操作命令
Redis:集合Set类型数据的操作命令
2022-07-04 03:52:00 【dengfengling999】
集合类型(set)
Redis的Set是string类型的无序不重复集合。
集合类型的数据操作总的思想是通过key确定集合,key是集合标识,元素没有下标,只有直接操作业务数据和数据的个数。
1.sadd
语法:sadd key member [member…]
功能:将一个或多个 member 元素加入到集合 key 当中,已经存在于集合的 member 元素将被忽略,不会再加入。
返回值:加入到集合的新元素的个数(不包括被忽略的元素)。
例如:
2.smembers
语法:smembers key
功能:获取集合 key 中的所有成员元素,不存在的key视为空集合。
返回值:返回指定集合的所有元素集合,不存在的key,返回空集合。
例如:
3.sismember
语法:sismember key member
功能:判断 member 元素是否是集合 key 的元素
返回值:member是集合成员返回1,其他返回 0 。
例如:
4.scard
语法:scard key
功能:获取集合里面的元素个数
返回值:数字,key的元素个数。其他情况返回 0 。
例如:
5.srem
语法:srem key member [member…]
功能:移除集合中一个或多个元素,不存在的元素被忽略。
返回值:数字,成功移除的元素个数,不包括被忽略的元素。
例如:
6.srandmember
语法:srandmember key[count]
功能:只提供key,随机返回集合中一个元素,元素不删除,依然在集合中;
提供了count时,count 正数, 返回包含count个数元素的集合,集合元素各不重复。count是负数,返回一个count绝对值的长度的集合,集合中元素可能会重复多次。
返回值:一个元素或者多个元素的集合
例如:count随机产生
count:随机产生的个数 count>0不重复 count<0有重复的
7.spop
语法:spop key[count]
功能:随机从集合中删除一个或count个元素。
返回值:被删除的元素,key不存在或空集合返回nil。
例如:
8.smove
语法:smove src dest member
功能:将 member 元素从src集合移动到dest集合,member不存在,smove不执行操作,返回0,如果dest存在member,则仅从src中删除member。
返回值:成功返回 1 ,其他返回 0 。
例如:
9.sdiff
语法:sdiff key key [key…]
功能:返回指定集合的差集,以第一个集合为准进行比较,即第一个集合中有但在其它任何集合中都没有的元素组成的集合。
返回值:返回第一个集合中有而后边集合中都没有的元素组成的集合,如果第一个集合中的元素在后边集合中都有则返回空集合。
例如:
10.sinter
语法:sinter key key [key…]
功能:返回指定集合的交集,即指定的所有集合中都有的元素组成的集合。
返回值:交集元素组成的集合,如果没有则返回空集合。
例如:刚开始3个集合没有工鞥用元素,然后当在set02加入e之后就有了共同的元素
11.sunion
语法:sunion key key [key…]
功能:返回指定集合的并集,即指定的所有集合元素组成的大集合,如果元素有重复,则保留一个。
返回值:返回所有集合元素组成的大集合,如果所有key都不存在,返回空集合。
例如:
边栏推荐
- 量子力学习题
- [Logitech] m720
- [book club issue 13] packaging format of video files
- Understand the principle of bytecode enhancement technology through the jvm-sandbox source code
- Evolution of MySQL database architecture
- leetcode刷题:二叉树07(二叉树的最大深度)
- 【CSRF-01】跨站请求伪造漏洞基础原理及攻防
- 程序员远程办公喜忧参半| 社区征文
- Katalon uses script to query list size
- idea修改主体颜色
猜你喜欢
Confession code collection, who says program apes don't understand romance
'2'&gt;' 10'==true? How does JS perform implicit type conversion?
透过JVM-SANDBOX源码,了解字节码增强技术原理
2020 Bioinformatics | TransformerCPI
10 reasons for not choosing to use free virtual hosts
Two commonly used graphics can easily realize data display
02 ls 命令的具体实现
Idea modify body color
Mitsubishi M70 macro variable reading Mitsubishi M80 public variable acquisition Mitsubishi CNC variable reading acquisition Mitsubishi CNC remote tool compensation Mitsubishi machine tool online tool
*. No main manifest attribute in jar
随机推荐
Why is the probability of pod increasing after IPtable
leetcode刷题:二叉树06(对称二叉树)
【华为云IoT】读书笔记之《万物互联:物联网核心技术与安全》第3章(上)
Myslq delete followed by limit
Flink学习6:编程模型
JS realizes the effect of text scrolling marquee
【愚公系列】2022年7月 Go教学课程 002-Go语言环境安装
Deep thinking on investment
Illustrated network: what is the hot backup router protocol HSRP?
疫情来袭--远程办公之思考|社区征文
I was tortured by my colleague's null pointer for a long time, and finally learned how to deal with null pointer
RHCSA 07 - 用户与群组管理
02 ls 命令的具体实现
Graduation summary
Redis cluster uses Lua script. Lua script can also be used for different slots
hbuildx中夜神模拟器的配置以及热更新
vim映射命令
Cesiumjs 2022^ source code interpretation [0] - article directory and source code engineering structure
*. No main manifest attribute in jar
Brief explanation of depth first search (with basic questions)