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

边栏推荐
- 新手找陪驾要注意什么
- 旭化成首次参展第五届中国国际进口博览会(5th CIIE)
- Touch and take you to implement an EventEmitter
- 微信公众号无限回调授权系统源码
- What does software testing do? Find defects and improve the quality of software
- 普源DS1000Z系列数字示波器在通信原理实验中的应用方案
- Apple CMS imitation watermelon video atmospheric response video template source code
- 一个漂亮的API文档生成工具
- C language bidirectional linked list first edition
- Common methods of threads
猜你喜欢
![[csrf-01] basic principle and attack and defense of Cross Site Request Forgery vulnerability](/img/46/cb5a10ffe3fcdffb7da68dbaef5b1f.png)
[csrf-01] basic principle and attack and defense of Cross Site Request Forgery vulnerability

指针数组和数组指针

dried food! Generation of rare samples based on GaN

Exercises in quantum mechanics

Distributed system: what, why, how

北漂程序员,月薪20K,一年攒15W,正常吗?

Leetcode skimming: binary tree 07 (maximum depth of binary tree)

Lnk2038 detected a mismatch of "runtimelibrary": the value "md_dynamicrelease" does not match the value "mdd_dynamicdebug" (in main.obj)

Main applications of TDK lambda power supply

Flink learning 6: programming model
随机推荐
Flink学习6:编程模型
Leetcode skimming: binary tree 09 (minimum depth of binary tree)
沃博联结束战略评估,决定保留表现优异的博姿业务
leetcode刷题:二叉树08(N叉树的最大深度)
hbuildx中夜神模拟器的配置以及热更新
Pytest basic self-study series (I)
ModStartBlog 现代化个人博客系统 v5.2.0 源码下载
Unity 绘制弹球和台球的运动轨迹
Why use node
(pointeur) Écrivez - vous une fonction qui compare la taille de la chaîne et fonctionne comme strcmp.
Flink learning 8: data consistency
TCP-三次握手和四次挥手简单理解
毕业三年,远程半年 | 社区征文
精品网址导航主题整站源码 wordpress模板 自适应手机端
最长递增子序列问题(你真的会了吗)
B. All Distinct
EIG在智利推出可再生能源平台Grupo Cerro
[Logitech] m720
Distributed system: what, why, how
疫情远程办公经验分享| 社区征文