当前位置:网站首页>Redis: order collection Zset type data operation command
Redis: order collection Zset type data operation command
2022-07-04 04:28:00 【dengfengling999】
single key : Multi order value
Orderly collection and consideration List aggregate ( Orderly , Order of insertion ) and Set aggregate ( disorder , Can't repeat ) Characteristics , But different from them
The elements of an ordered set are associated with a fraction ,redis It will automatically sort according to this score , By default, they are sorted from small to large
Ordered set type (Zset)
Redis Ordered set zset And collection set The same is true. string Collection of type elements , And duplicate members are not allowed .
The difference is zset Each element of the is associated with a score ( Scores can be repeated ),redis Sort the members of the set from small to large by score .
1.zadd
grammar :zadd key score member [score member…]
function : Put one or more member Elements and score Values are added to the ordered set key in , If member In the collection , Then overwrite the original value ;score It can be an integer or floating point number .
Return value : Numbers , Number of newly added elements .
for example :
2.zrange
grammar :zrange key startIndex endIndex [WITHSCORES]
function : Query ordered sets , The elements in the specified interval . Set members by score Sort values from small to large ;startIndex and endIndex from 0 Start with the first element ,1 For the second element , And so on ; startIndex and endIndex You can take negative numbers , Take from the back to the front ,-1 Represents the last but one element ;WITHSCORES Option to score and value Come back together .
Return value : A set of members of a specified interval .
for example :
Return with scores :value and score
3.zrangebyscore
grammar :zrangebyscore key min max [WITHSCORES ] [LIMIT offset count]
function : Get ordered set key in , all score The value is between min and max Between ( Include min and max) Members of , Ordered members are incremented ( From small to large ) Sort ;
Using symbols ”(“ Means to include min But does not include max;
withscores Show score and value;
limit Used to limit the number and interval of returned results , In the result set from offset Start , take count individual .
Return value : Set data of specified interval
for example :
4.zrem
grammar :zrem key member [member…]
function : Delete ordered collection key One or more members of , Nonexistent members are ignored .
Return value : Number of members successfully deleted , Excluding ignored members .
for example :
5.zcard
grammar :zcard key
effect : Get ordered set key The number of element members of .
Return value :key There is , Returns the number of collection elements ; key non-existent , return 0.
for example :
6.zcount
grammar :zcount key min max
function : Return to ordered set key in , score Values in min and max Between ( Include score The value is equal to min or max ) The number of members of .
Return value : Specifies the number of elements in an ordered set whose fraction is within a specified interval .
for example :
7.zrank
grammar :zrank key member
function : Get ordered set key Member of the member Ranking , Members of the ordered set press score The values are arranged in descending order , from 0 Start ranking ,score The smallest is 0 .
Return value : Specifies the ranking of elements in an ordered set ; If the specified element does not exist , return nil.
for example :
8.zscore
grammar :zscore key member
function : Get the ordered set key Medium element member The scores of .
Return value : Returns the fraction of the elements of the specified ordered set .
for example :
9.zrevrank
grammar :zrevrank key member
function : Get ordered set key Member of the member Ranking , Members of the ordered set press score The values are arranged in descending order , from 0 Start ranking ,score The biggest thing is 0 .
Return value : Specifies the ranking of elements in an ordered set ; If the specified element does not exist , return nil.
for example :
10.zrevrange
grammar :zrevrange key startIndex endIndex [WITHSCORES]
function : Query ordered sets , The elements in the specified interval . Set members by score Sort values from large to small ;startIndex and endIndex from 0 Start with the first element ,1 For the second element , And so on ; startIndex and endIndex You can take negative numbers , Take from the back to the front ,-1 Represents the last but one element ;WITHSCORES Option to score and value Come back together .
Return value : A set of members of a specified interval .
11.zrevrangebyscore
grammar :zrevrangebyscore key max min [WITHSCORES ] [LIMIT offset count]
function : Get ordered set key in , all score The value is between max and min Between ( Include max and min) Members of , The order of members is decreasing ( From big to small ) Sort ;
Using symbols ”(“ Means not to include min and max;
withscores Show score and value;
limit Used to limit the number and interval of returned results , In the result set from offset Start , take count individual .
Return value : Set data of specified interval
边栏推荐
- y55.第三章 Kubernetes从入门到精通 -- HPA控制器及metrics-server(二八)
- [webrtc] M98 Ninja build and compile instructions
- 02 specific implementation of LS command
- VIM mapping command
- Flink学习8:数据的一致性
- 新手找陪驾要注意什么
- leetcode刷题:二叉树06(对称二叉树)
- C language bidirectional linked list first edition
- MIN_RTO 对话
- 01 QEMU starts the compiled image vfs: unable to mount root FS on unknown block (0,0)
猜你喜欢
微信脑力比拼答题小程序_支持流量主带最新题库文件
EventBridge 在 SaaS 企业集成领域的探索与实践
What does software testing do? Find defects and improve the quality of software
96% of the collected traffic is prevented by bubble mart of cloud hosting
2020 Bioinformatics | TransformerCPI
疫情远程办公经验分享| 社区征文
TCP-三次握手和四次挥手简单理解
[csrf-01] basic principle and attack and defense of Cross Site Request Forgery vulnerability
最长递增子序列问题(你真的会了吗)
ModStartBlog 现代化个人博客系统 v5.2.0 源码下载
随机推荐
指针数组和数组指针
What does software testing do? Find defects and improve the quality of software
Unity 绘制弹球和台球的运动轨迹
Pointer array and array pointer
tdk-lambda电源主要应用
[microservice openfeign] use openfeign to remotely call the file upload interface
微信脑力比拼答题小程序_支持流量主带最新题库文件
Unity Resource path
MIN_RTO 对话
The interactive solution of JS and app in the H5 page embedded in app (parameters can be transferred and callbacks can be made)
Graduation project: design seckill e-commerce system
2020 Bioinformatics | TransformerCPI
A beautiful API document generation tool
One click compilation and deployment of MySQL
【云原生】那些看起来很牛X,原理却很简单的一行代码
【微服务|openfeign】feign的两种降级方式|Fallback|FallbackFactory
y55.第三章 Kubernetes从入门到精通 -- HPA控制器及metrics-server(二八)
一位毕业生的自我分享
毕业设计项目
架构训练毕业设计+总结