当前位置:网站首页>Redis(六)-Redis的常用数据类型之Set集合
Redis(六)-Redis的常用数据类型之Set集合
2022-04-22 13:39:00 【码农飞哥】
您好,我是码农飞哥,感谢您阅读本文,欢迎一键三连哦。
1. Python基础专栏,基础知识一网打尽,9.9元买不了吃亏,买不了上当。 Python从入门到精通
️ 2. Python爬虫专栏,系统性的学习爬虫的知识点。9.9元买不了吃亏,买不了上当,持续更新中 。python爬虫入门进阶
️ 3. Ceph实战,从原理到实战应有尽有。 Ceph实战
️ 4. Java高并发编程入门,打卡学习Java高并发。 Java高并发编程入门
5. 社区逛一逛,周周有福利,周周有惊喜。码农飞哥社区,飞跃计划
全网同名【码农飞哥】欢迎关注,个人VX: wei158556
简介
Redis set 对外提供的功能与list类似,唯一的不同就是set可以自动去重,当你需要存储一个列表数据,但是又不希望出现重复数据时,set是一个很好的选择。并且set提供了判断某个成员是否在一个set集合内的重要接口,这个也是list所不能提供的。
Redis 的Set 是String类型的无序集合,它底层其实是一个value为null的hash表,所添加,删除,查找的复杂度都是O(1)。
常用命令
- 将一个或多个元素加入到集合key中,已经存在的元素将被忽略。
sadd <key> <value1> <value2> .....
- 取出该集合中的所有值。
smembers <key>
- 判断集合
<key>是否为含有该<value>值,有的话返回1,没有的话返回0
sismember <key> <value>
- 返回该集合的元素个数
scard <key>

5. 删除集合中的某个元素
srem <key> <value1> <value2> .....
- 随机从该集合中吐出一个值
#随机吐出一个值
spop <key>
#随机吐出n个值
spop <key> <n>

7. 随机从该集合中取出n个值,不会从集合中删除。
srandmember <key> <n>

8. 把集合中一个值从一个集合移动到另一个集合
smove <source> <destination> <value>

9. 返回两个集合的交集元素
sinter <key1> <key2>
- 返回两个集合的并集元素
sunion <key1> <key2>
- 返回两个集合的差集元素(key1中的,不包含key2中的)
sdiff <key1> <key2>

数据结构
Set 数据结构是dict字典,字典是用哈希表实现的。
Java中的HashSet的内部实现使用的是HashMap,只不过所有的value都指向同一个对象
Redis的set结构也是一样,它的内部也使用hash结构,所有的value都指向同一个内部值。
参考
《Redis的设计与实现》
Redis基本类型及其数据结构
版权声明
本文为[码农飞哥]所创,转载请带上原文链接,感谢
https://feige.blog.csdn.net/article/details/124319156
边栏推荐
- 关于chartjs 屏幕大小自适应
- PHP 零基础入门笔记(12):数组 array
- Can ainai get out of the dilemma by 35 billion yuan?
- MapReduce case - join operation is realized through the reduce side and the map side respectively
- BAIC Foton, Sinopec and light engineering Internet of things set up Sinopec to sell hydrogen energy (Beijing)
- 5分钟快速了解MySQL索引的各种类型
- Rust implements Fibonacci number
- What are the types of blocking queues in the thread pool?
- 高管团队异质性和稳定性数据(含代码、计算过程及原始数据)
- Redisconfig configuration class
猜你喜欢

Good collection (1)

Algorithm --- reverse linked list (kotlin)
BAIC Foton, Sinopec and light engineering Internet of things set up Sinopec to sell hydrogen energy (Beijing)

Citrix SQL数据如何进行多表联查

【Flutter 专题】91 图解 Dart 单线程实现异步处理之 Future (二) #yyds干货盘点#

上市公司营业收入数据集(1990-2021第三季度)

Heterogeneity and stability data of senior management team (including code, calculation process and original data)

好物合集(1)
[live broadcast attack] the oneos system tutorial is fully launched. We invite you to study with ST and oneos!

“开源之夏”活动火热报名中,丰厚奖金等你来拿
随机推荐
Panel data of provincial innovation capacity - including multi index data such as number of patents and turnover (2008-2019)
What saved me 60% of my coding time? Use MBG
MySQL8.0学习记录08 - 数据类型默认值
How does redis view the memory size occupied by a single key
Applet to share with friends list and circle of friends
“开源之夏”活动火热报名中,丰厚奖金等你来拿
mysql FUNCTION xxx. CHARINDEX does not exist
POJ 3259 shortest SPFA + negative ring (template)
Can ainai get out of the dilemma by 35 billion yuan?
CDF全球调查:软件交付性能停滞不前
Partition - elegant violence
POJ 3259 最短路SPFA + 负环 (模板)
PM4PY - BPMN support
中英文会计&金融情绪词典
启牛学堂让下载蜻蜓点金开户,才能继续在学习?可以下载嘛?安全吗?
MapReduce案例—分别通过Reduce端和Map端实现JOIN操作
如何开启Apache SkyWalking的自监控?
C# 7.0 使用下划线忽略使用的变量
The "open source summer" activity is hot. In the registration, rich bonuses are waiting for you to get
[zeekr_tech] Introduction to ros/ros 2