当前位置:网站首页>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
边栏推荐
- 2022.4.10-----leetcode. eight hundred and four
- RuntimeError: The size of tensor a (4) must match the size of tensor b (3) at non-singleton dimensio
- Is it better to use a physical machine or a virtual machine to build a website?
- Dynamic memory management
- Ziguang micro financial report is outstanding. What does the triple digit growth of net profit in 2021 depend on
- Is CICC fortune a company with CICC? Is it safe
- Halo open source project learning (I): project launch
- 拨号服务器是什么,有什么用处?
- What categories do you need to know before using proxy IP?
- Esp32 message queue using FreeRTOS
猜你喜欢

C语言中如何“指名道姓”的进行初始化

CC2541的仿真器CC Debugger使用教程

What is a proxy IP pool and how to build it?

Realize linear regression with tensorflow (including problems and solutions in the process)

How does Axure set the content of the text box to the current date when the page is loaded

Leetcode46 Full Permutation

RuntimeError: The size of tensor a (4) must match the size of tensor b (3) at non-singleton dimensio

Do447 manage user and team access

Performance introduction of the first new version of cdr2022

Leetcode 112 Total path (2022.04.22)
随机推荐
Shardingsphere broadcast table and binding table
一些使用代理IP的小技巧。
How to configure iptables to realize local port forwarding
Encrypted compressed backup bat script
Dimension C China helping farmers in rural areas warms people's hearts the third stop is jiabaoguo farm
Realize linear regression with tensorflow (including problems and solutions in the process)
揭秘被Arm编译器所隐藏的浮点运算
Do447 manage user and team access
Redis memory recycling strategy
2022.4.10-----leetcode.804
什么是代理IP池,如何构建?
在使用代理IP前需要了解哪些分类?
Heap overflow of kernel PWN basic tutorial
How to classify proxy IP?
什么是api接口?
2022 crane driver (limited to bridge crane) examination question bank and online simulation examination
What is a boolean type?
一加一为什么等于二
Basic knowledge of software testing, you can meet the interviewer after reading it
Some tips for using proxy IP.