当前位置:网站首页>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

边栏推荐
- Krypton saikr daily question - CTF
- UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0x98 in position 1093: illegal multibyte sequence
- Redis:哈希hash类型数据操作命令
- Architecture practice camp - graduation project of module 9 of phase 6
- 分布式CAP理论
- 虚拟商品帐号交易平台源码_支持个人二维码收款
- 一位毕业生的自我分享
- [microservice openfeign] @feignclient detailed explanation
- Interpretation of leveldb source code skiplist
- 如何远程办公更有效率 | 社区征文
猜你喜欢

Architecture training graduation design + summary

PPt 教程,如何在 PowerPoint 中将演示文稿另存为 PDF 文件?
![[Logitech] m720](/img/bb/44144a1c3907808398c05b3b36962c.png)
[Logitech] m720

Idea modify body color

多位科技公司创始人向Entrepreneur First提供高达1.58亿美元的C轮融资,协助其投资下一代全球创新者

微信公众号无限回调授权系统源码

Leetcode skimming: binary tree 08 (maximum depth of n-ary tree)

Flink学习6:编程模型

什么是上下文?

Keysight N9320B射频频谱分析仪解决轮胎压力监测方案
随机推荐
Flink learning 8: data consistency
Dry goods | detailed explanation of webshell Foundation
I.MX6U-ALPHA开发板(C语言版本LED驱动实验)
How to add custom API objects in kubernetes (1)
指针数组和数组指针
NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线
NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线
毕业设计:设计秒杀电商系统
leetcode 121 Best Time to Buy and Sell Stock 买卖股票的最佳时机(简单)
Redis:集合Set类型数据的操作命令
Keysight N9320B射频频谱分析仪解决轮胎压力监测方案
Restore the subtlety of window position
JS实现文字滚动 跑马灯效果
Leetcode brush question: binary tree 06 (symmetric binary tree)
博朗与Virgil Abloh于2021年为纪念博朗品牌100周年而联合打造的“功能性艺术”将在博物馆展出Abloh作品期间首次亮相
leetcode刷题:二叉树09(二叉树的最小深度)
沃博联结束战略评估,决定保留表现优异的博姿业务
Three years of graduation, half a year of distance | community essay solicitation
浅谈一篇优质的小红书文案需要具备什么
分布式CAP理论