当前位置:网站首页>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
边栏推荐
- How to set computer IP?
- Unicorn bio raised $3.2 million to turn prototype equipment used to grow meat into commercial products
- What businesses use physical servers?
- Is CICC fortune a company with CICC? Is it safe
- Is CICC fortune a state-owned enterprise and is it safe to open an account
- How to call out services in idea and display the startup class in services
- 《维C中国》乡村助农暖人心第三站嘉宝果农场
- Problem solving: dpkg DEB: error: package name has characters that are't lowercase alphanums or '- +‘
- Shardingsphere introduction and sub table usage
- Today will finally write system out. Println()
猜你喜欢

Encrypted compressed backup bat script

How to classify proxy IP?

leetcode:27. 移除元素【count remove小操作】

89 logistic回归用户画像用户响应度预测

FL studio20. 8 the latest Chinese version installation and download graphic tutorial

拨号服务器是什么,有什么用处?

89 logistic回歸用戶畫像用戶響應度預測

Is it better to use a physical machine or a virtual machine to build a website?

What is an API interface?

Shardingsphere read write separation
随机推荐
How to install mysql-5.7.9 in RPM mode under Linux system
What categories do you need to know before using proxy IP?
ThinkPHP kernel development blind box mall source code v2 0 docking easy payment / Alibaba cloud SMS / qiniu cloud storage
今天终于会写System.out.println()了
Shardingsphere broadcast table and binding table
世界读书日 | 技术人不要错过的好书(IT前沿技术)
How to choose a good dial-up server?
Micro build low code zero foundation introductory course
What are the common proxy IP problems?
Is the sinking coffee industry a false prosperity or the eve of a broken situation?
NPM -- configure Taobao image
What are the test steps of dynamic proxy IP?
Nanny level tutorial on building personal home page (II)
ESP32使用freeRTOS的消息队列
Use Xdebug breakpoint debugging in postman
What is an API interface?
OJ daily practice - Finish
搭建网站是用物理机还是云主机好?
Virtual serial port function of j-link V9 using skills
keil mdk中文乱码,两种解决方法,字体不再难看