当前位置:网站首页>Set of redis data structure
Set of redis data structure
2022-06-22 18:38:00 【Sword Saint without trace】
Keep creating , Accelerate growth ! This is my participation 「 Nuggets day new plan · 6 Yuegengwen challenge 」 Of the 27 God , Click to see the event details
brief introduction
Reids Of set It's a collection type , You can save multiple string elements , Elements in a collection cannot be repeated , And the elements in the set are also unordered , Cannot get elements in a collection by subscript , These characteristics are related to java Of set Very similar .
data structure
Redis Of set The bottom layer uses intset and hashtable Two data structures are used to store data , among intset It can be understood as a special array , and hashtable It's an ordinary hash table .
Set Underlying storage intset and hashtable Code conversion exists , Use intset Storage must meet the following two conditions , Otherwise use hashtable, The conditions are as follows :
- 1. All elements saved by the combined object are integer values
- 2. The collection object holds no more elements than 512 individual
hashtable data structure
hashtable The data structure is the same as that in the previous chapter Hash The structure in is basically the same , This chapter will not repeat the description .
intSet data structure
explain :
- encoding:contents The type of data saved , The default type is int16_t.
- contents: Actual content array
- length:contents The number of elements
Basic commands
sadd Additive elements
Basic grammar
sadd key value1...valuen
Example
scard Get the number of members of the collection
Basic grammar
scard key
Example
sdiff Get the difference between the set and the set
Basic grammar
sdiff key1 key2
Example
sinter Get the intersection of a set and a set
Basic grammar
sinter key1 key2
Example
sismember Judge member Is the element a collection key Members of
Basic grammar
sismember key member
Example
smembers Get all members of the collection
Basic grammar
smembers key
Example
sunion Get the union of all the given sets
Basic grammar
sunion key1 key2
Example
srem Remove one or more elements
Basic grammar
srem key member
Example
sscan Elements in iteration set
Basic grammar
sscan key cursor [match pattern] count
explain :
- cursor: The cursor , from 0 Start
- pattern : Matching mode
- count: Specifies how many elements to return from the dataset , The default value is 10.
Example
sscan mset 0 match j*
Application scenarios
- Counting cell phones App Number of new users per day
key With user:id And the date of the day , for example user:id:20200803; value by Set aggregate , Record the users logged in on that day ID.
Blog mutual friend
adopt set Get the intersection of multiple sets .
Webpage UV The statistics of
Count the number of times a user visits a web page every day , A user's multiple visits in a day can only be counted as one .
matters needing attention
use Set For some large sets of related accurate statistics , Very inefficient , High memory overhead , Try to avoid in the production environment .
summary
This chapter explains Redis Data structure of Set, We need to pay attention to redis Of set Usage scenarios for aggregation operations , If you have any questions, please feel free to give feedback .
边栏推荐
- SaaS化应用开发指南
- Azkaban startup error 2022/06/20 21:39:27.726 +0800 error [stdouterrredirect] [azkaban] exception in thread "m
- 请问一下,CDC2.0在读取mysql的时候,应该是没有表锁了吧,刚刚报了一个错误,access d
- Make it more automatic to transfer slow logs and audit logs of RDS (for MySQL) databases to OBS across spaces
- Unity中通过射线躲避障碍物寻路的一些初步探索
- 新东方转型双语直播带货给项目管理人的一场课
- 2022年T电梯修理复训题库及答案
- Game NFT Market: opensea's most easily cut cake
- 问下 cdc 2.2.1监控sqlServer是不支持监控多库的吗?
- d的dip1000,1
猜你喜欢
Golang实现基于Redis的可靠延迟队列

The Fourth Youth Life Science Forum | first round notice

Five practical tips for power Bi (complimentary books at the end of the article)

When do project managers particularly want to escape from work?

Nuxt - 超详细环境搭建及创建项目整体流程(create-nuxt-app)

Binary tree practice the second bullet

项目经理们在哪个时刻特别想逃离工作?

2022年R2移动式压力容器充装试题模拟考试平台操作

< JVM part I: memory and garbage collection part > 08 object instantiation and direct memory

新手必会的静态站点生成器——Gridsome
随机推荐
Static linked list (I)
自定义数据库连接池类: 要求:封闭一个Collection对象的集合类
centerOS 安装mangodb
CONDA - basic configuration command summary
缺失值处理
Power BI的五个实用小技巧(文末赠书)
Preliminary controller input of oculus learning notes (1)
Array emulation stack
azkaban启动报错 2022/06/20 21:39:27.726 +0800 ERROR [StdOutErrRedirect] [Azkaban] Exception in thread “m
docker: Error response from daemon: Conflict. The container name “/mysql“ is already in use by conta
预约打新债哪个券商公司开户好,开账户是更安全呢
Jenkins installation and upgrade
Jenkins中node节点添加之SSH方式2
[轻松学会shell编程]-4、单引号和双引号的区别、整形数值的运算、shell中数组定义和sed的详细用法
2022年R2移动式压力容器充装试题模拟考试平台操作
Excuse me, when cdc2.0 reads mysql, there should be no table lock. An error was just reported, access D
数组实现循环链表
2022焊工(初级)特种作业证考试题库模拟考试平台操作
TypeScript(7)泛型
Huawei cloud "digital intelligence" operation and maintenance