当前位置:网站首页>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都不存在,返回空集合。
例如:
边栏推荐
- 02 ls 命令的具体实现
- I Build a simple microservice project
- [paddleseg source code reading] paddleseg calculation dice
- JDBC 进阶
- 深度优先搜索简要讲解(附带基础题)
- Interpretation of leveldb source code skiplist
- 程序员远程办公喜忧参半| 社区征文
- 量子力学习题
- Why is the probability of pod increasing after IPtable
- Illustrated network: what is the hot backup router protocol HSRP?
猜你喜欢
Tcpclientdemo for TCP protocol interaction
leetcode刷题:二叉树09(二叉树的最小深度)
透过JVM-SANDBOX源码,了解字节码增强技术原理
Flink learning 7: application structure
Idea modify body color
Confession code collection, who says program apes don't understand romance
Understand the principle of bytecode enhancement technology through the jvm-sandbox source code
Flink学习7:应用程序结构
How to telecommute more efficiently | community essay solicitation
User defined path and file name of Baidu editor in laravel admin
随机推荐
如何远程办公更有效率 | 社区征文
Graduation project: design seckill e-commerce system
10 reasons for not choosing to use free virtual hosts
指针数组和数组指针
The new data center helps speed up the construction of a digital economy with data as a key element
Rhcsa-- day one
How to telecommute more efficiently | community essay solicitation
量子力学习题
三菱M70宏变量读取三菱M80公共变量采集三菱CNC变量读取采集三菱CNC远程刀补三菱机床在线刀补三菱数控在线测量
[Logitech] m720
96% of the collected traffic is prevented by bubble mart of cloud hosting
ROS2中CMake编译选项的设置
软件测试是干什么的 发现缺陷错误,提高软件的质量
TCP-三次握手和四次挥手简单理解
JDBC advanced
Getting started with the go language is simple: go implements the Caesar password
Katalon中控件的参数化
【webrtc】m98 ninja 构建和编译指令
ctf-pikachu-CSRF
透过JVM-SANDBOX源码,了解字节码增强技术原理