当前位置:网站首页>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
边栏推荐
- RHCSA 03 - 文件的基础权限
- 沃博联结束战略评估,决定保留表现优异的博姿业务
- Modstartblog modern personal blog system v5.2.0 source code download
- Redis:有序集合zset类型数据操作命令
- [Logitech] m720
- Wechat brain competition answer applet_ Support the flow main belt with the latest question bank file
- 一位毕业生的自我分享
- Restore the subtlety of window position
- 分布式CAP理论
- 西部数据绿盘、蓝盘、黑盘、红盘和紫盘有什么区别
猜你喜欢
Redis:哈希hash类型数据操作命令
精品网址导航主题整站源码 wordpress模板 自适应手机端
Redis:有序集合zset类型数据操作命令
Boutique website navigation theme whole station source code WordPress template adaptive mobile terminal
Modstartblog modern personal blog system v5.2.0 source code download
疫情远程办公经验分享| 社区征文
leetcode刷题:二叉树05(翻转二叉树)
Leetcode skimming: binary tree 04 (sequence traversal of binary tree)
Distributed system: what, why, how
02 specific implementation of LS command
随机推荐
NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线
The interactive solution of JS and app in the H5 page embedded in app (parameters can be transferred and callbacks can be made)
Main applications of TDK lambda power supply
程序员远程办公喜忧参半| 社区征文
指针数组和数组指针
统计遗传学:第三章,群体遗传
Touch and take you to implement an EventEmitter
A beautiful API document generation tool
Use NRM and NVM to manage your NPM source and node versions
TCP-三次握手和四次挥手简单理解
【愚公系列】2022年7月 Go教学课程 001-Go语言前提简介
Redis:哈希hash类型数据操作命令
Katalon uses script to query list size
Flink学习8:数据的一致性
How to telecommute more efficiently | community essay solicitation
北漂程序员,月薪20K,一年攒15W,正常吗?
[microservices openfeign] two degradation methods of feign | fallback | fallbackfactory
Leader: who uses redis expired monitoring to close orders and get out of here!
精品网址导航主题整站源码 wordpress模板 自适应手机端
B. All Distinct