当前位置:网站首页>006_redis_SortedSet类型
006_redis_SortedSet类型
2022-04-23 02:02:00 【_yummy_】
006_redis_SortedSet类型
1、是一个可排序的set集合,与java中的treeset类似。但是底层的数据结构却差别很大。
- SortedSet中每一个元素都带有一个score的属性,可以基于score属性对元素进行排序
- 底层实现是一个跳表(SkipList)加hash表
2、SortedSet具备的特性
- 无序
- 元素不可重复
- 查询速度快
总结:由于SortedSet的可排序性,经常被用来实现排行版这一类的功能。
3、SortedSet类型常见的命令
- ZADD:添加一个或多个元素
- ZREM:删除一个指定元素
- ZSCORE:获取集合中指定元素额score值
- ZRANK:获取指定元素的排序
- ZCARD:获取集合中元素的个数
- ZCOUNT:统计score值在给定范围内的所有元素的个数
- ZINCREBY:指定元素自增
- ZRANGE:根据score进行排序之后,获取指定排名范围内的元素
- ZDIFF、ZINTER、ZUNION:差集、交集、并集
注意:所有的排名默认都是升序的,如果需要设置降序操作,需要在Z后面添加REV即可。比如:ZREVRANK
(1)测试练习
127.0.0.1:6379> zadd stus 85 jack 89 lucy 82 rose 95 tom 78 jerry 76 Miles
(integer) 6
127.0.0.1:6379> zrem stus tom
(integer) 1
- 获取rose同学的排名
返回的排名是从0开始的。
127.0.0.1:6379> zrank stus rose
(integer) 2
127.0.0.1:6379> zrevrank stus rose
(integer) 2
- 查询80以下有多少人
127.0.0.1:6379> zcount stus 0 80
(integer) 2
- 给Rose同学加2分
127.0.0.1:6379> zincrby stus 2 rose
"84"
- 查出成绩前三的同学(默认升序,需要逆转rev)
127.0.0.1:6379> zrevrange stus 0 2
1) "lucy"
2) "jack"
3) "rose"
- 查出成绩80分以下的所有同学
127.0.0.1:6379> zrangebyscore stus 0 80
1) "Miles"
2) "jerry"
版权声明
本文为[_yummy_]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_43890515/article/details/124300038
边栏推荐
- Makefile文件是什么?
- Echo "new password" |passwd -- stdin user name
- 紫光国微财报一枝独秀 2021年净利润三位数增长靠什么
- Dynamic batch processing and static batch processing of unity
- 搭建网站是用物理机还是云主机好?
- 【dpdk】10. Dpdk DNS learning notes
- Unity editor hierarchy drop-down menu extension
- leetcode:27. Remove element [count remove]
- Encrypted compressed backup bat script
- 如何选择一台好的拨号服务器?
猜你喜欢
紫光国微财报一枝独秀 2021年净利润三位数增长靠什么
How to "gracefully" measure system performance
2022 Saison 6 perfect Kid Model IPA national race Leading the Meta - Universe Track
如何对代理IP进行分类?
一些使用代理IP的小技巧。
Dimension C China helping farmers in rural areas warms people's hearts the third stop is jiabaoguo farm
Analyze the advantages and disadvantages of tunnel proxy IP.
89 logistic回归用户画像用户响应度预测
RuntimeError: The size of tensor a (4) must match the size of tensor b (3) at non-singleton dimensio
MySQL basic record
随机推荐
How to call out services in idea and display the startup class in services
【动手学深度学习V2】循环神经网络-1.序列模型
How to choose a good dial-up server?
Network jitter tool clumsy
The leader / teacher asks to fill in the EXCEL form document. How to edit the word / Excel file on the mobile phone and fill in the Excel / word electronic document?
App optimization and advanced scoreboard Part 2 [Mui + flask + mongodb]
Challenges often faced by client project management
Is the sinking coffee industry a false prosperity or the eve of a broken situation?
What categories do you need to know before using proxy IP?
Some tips for using proxy IP.
今天终于会写System.out.println()了
动态代理ip的测试步骤有哪些?
Uncover floating-point operations hidden by the ARM compiler
Why is one plus one equal to two
How to install mysql-5.7.9 in RPM mode under Linux system
关于局域网浅谈
Chinese scientists reveal a new mechanism for breaking through the bottleneck of rice yield
What problems will you encounter when dialing VPS?
2022.4.22-----leetcode. three hundred and ninety-six
什么是bgp服务器,有哪些优势?