当前位置:网站首页>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
边栏推荐
- Basic knowledge of software testing, you can meet the interviewer after reading it
- How can e-procurement become a value-added function in the supply chain?
- J-Link RTT使用
- 2022.4.20-----leetcode. three hundred and eighty-eight
- Leetcode 112 Total path (2022.04.22)
- What are the common proxy IP problems?
- Error in face detection and signature of Tencent cloud interface
- 2022 Saison 6 perfect Kid Model IPA national race Leading the Meta - Universe Track
- J-link v9 使用技巧之虚拟串口功能
- Under the pressure of sales, domestic mobile phones began to reduce prices, but they haven't put down their final face
猜你喜欢

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

浅析静态代理ip的三大作用。

教程】如何用GCC“零汇编”白嫖MDK

What businesses use physical servers?

我国科学家揭示突破水稻产量瓶颈新机制

Longest common subsequence (record path version)

How to call out services in idea and display the startup class in services

Use of j-link RTT

Analyze the three functions of static proxy IP.

搭建网站是用物理机还是云主机好?
随机推荐
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?
RuntimeError: The size of tensor a (4) must match the size of tensor b (3) at non-singleton dimensio
Dynamic memory management
Log4j2 configuration
Introduction to micro build low code zero Foundation (lesson 2)
A simple and open source navigation website source code
Dynamic batch processing and static batch processing of unity
How to classify proxy IP?
用TensorFlow实现线性回归(包括过程中出现的问题及解决方法)
How to change the size of SVG pictures without width in openlayer
浅析一下隧道代理IP的优缺点。
What is BGP server and what are its advantages?
2018 China Collegiate Programming Contest - Guilin Site J. stone game
What categories do you need to know before using proxy IP?
Chinese scientists reveal a new mechanism for breaking through the bottleneck of rice yield
PHP & laravel & master several ways of generating token by API and some precautions (PIT)
Cc2541 emulator CC debugger tutorial
单片机和4G模块通信总结(EC20)
EBS:PO_ EMPLOYEE_ HIERARCHIES_ ALL
如何设置电脑ip?