当前位置:网站首页>【Redis】Set类型
【Redis】Set类型
2022-06-29 01:56:00 【骑着蜗牛ひ追导弹'】
一、Set类型
Redis中的Set类型与java中的HashSet类似,可以看做是一个value为null的HashMap,具备和HashMap相类似的特征:
- 无序
- 元素不可以重复
- 查找快
- 支持交集、并集、差集等功能

基本的通用命令如上图所示,下面进行详细介绍!
1.1 SADD & SREM & SCARD

SADD key member …:向set中添加一个或多个元素
SREM key member …:移除set中的指定元素
SCARD key:返回set中元素的个数

1.2 SISMEMBER & SMEMBERS

- SISMEMBER key member:判断一个元素是否存在与set中
- SMEMBERS key :获取set中所有的元素

1.3 SINTER & SDIFF & SUNION
SINTER key1 key2 …:求key1与key2的交集

SDIFF key1 key2 …:求key1与key2的差集

SUNION key1 key2 …:求key1和key2的并集

案例:将下列数据用Redis的Set集合来存储:·张三的好友有:李四、王五、赵六;李四的好友有:王五、麻子、二狗利用Set的命令实现下列功能:

- 计算张三的好友有几人

- 计算张三和李四有哪些共同好友

- 查询哪些人是张三的好友却不是李四的好友

- 查询张三和李四的好友总共有哪些人

- 判断李四是否是张三的好友

- 判断张三是否是李四的好友

- 将李四从张三的好友列表中移除

边栏推荐
- Share the code technology points and software usage of socket multi client communication
- Basic use of Sqlalchemy
- 如何成为一名高级数字 IC 设计工程师(4-3)脚本篇:C 语言实现的文件读写操作
- Large scale visual relationship understanding
- How to use PN junction to measure temperature?
- 微信运动自动点赞
- 想请教股票开户要认识谁?现在网上开户安全么?
- Edrawmax mind map, edrawmax organization chart
- When you complain about the roll, others have quietly begun to prepare for the golden three silver four
- 基于 FPGA 的 RISC CPU 设计(4)关于项目的 36 个问题及其答案
猜你喜欢

4276. good at C
Scala 基础 (三):运算符和流程控制

Analysis of advantages and disadvantages of environment encryption and transparent encryption

OculusRiftS与Unity.UI的交互(1)-总览

如何成为一名高级数字 IC 设计工程师(4-3)脚本篇:C 语言实现的文件读写操作

C language course design - food warehouse management system
![[image detection] recognition of the front and back of a coin based on texture features with matlab code attached](/img/61/1fb15e9defa1fc471c4d2d34cc1ed4.jpg)
[image detection] recognition of the front and back of a coin based on texture features with matlab code attached

ASP. Design and implementation of net+sql online alumni list
Fundamentals of scala (3): operators and process control

The metadata request parsing principle of OData XML format applied by SAP ui5 is based on domparser
随机推荐
I'd like to ask you, where can I open an account in Zhongshan? Is it safe to open an account online?
A full screen gesture adaptation scheme
[从零开始学习FPGA编程-50]:视野篇 - 芯片是如何被制造出来的?芯片制造的十三大步骤。
如何成为一名高级数字 IC 设计工程师(5-1)理论篇:时钟技术、复位技术
我把整个研发中台拆分过程的一些心得总结
Analysis of advantages and disadvantages of environment encryption and transparent encryption
数字 IC 设计、FPGA 设计秋招笔试题目、答案、解析(2)2021 华为海思(上)
TypeScript(6)函数
Design and development of VB mine sweeping game
Typescript (6) function
如何成为一名高级数字 IC 设计工程师(6-4)数字 IC 验证篇:测试点分解
[C language] Fibonacci sequence and frog jumping steps (the most detailed elementary frog jumping steps)
Redis data migration (III)
Share the code technology points and software usage of socket multi client communication
Necessary technologies for chip manufacturers (1) Introduction
如何成为一名高级数字 IC 设计工程师(6-5)数字 IC 验证篇:覆盖率收集
Analysis of sending principle of OData metadata request for SAP ui5 application
Analysis of parsing principle of OData metadata request response in SAP ui5 application
Blog publishing test 3
In MySQL database, the two data written when creating tables with foreign keys are the same. Do I copy them or fail to display them