当前位置:网站首页>Redis基本类型-有序集合Zset
Redis基本类型-有序集合Zset
2022-07-24 05:31:00 【生命不止、战斗不息】
有序集合Zset:在set基础上,加一个score值。之前set是k1 v1 v2 v3,现在zset是 k1 score1 v1 score2 v2
#============================
# zadd 将一个或多个成员元素及其分数值加入到有序集当中
# zrange 返回有序集中 指定区间内的成员
#============================
127.0.0.1:6379> zadd myset 1 one
(integer) 1
127.0.0.1:6379> zadd myset 2 two 3 three
(integer) 2
127.0.0.1:6379> zrange myset 0 -1
1) "one"
2) "two"
3) "three"
#============================
# zrangebyscore 返回有序集合中指定分数区间的成员列表 有序集成员按分数值递增(从小到大)次序排列
#============================
127.0.0.1:6379> zadd salary 2500 lmp
(integer) 1
127.0.0.1:6379> zadd salary 500 hyd
(integer) 1
127.0.0.1:6379> zadd salary 5000 wyt
(integer) 1#inf无穷大 同样 -inf 无穷小
127.0.0.1:6379> zrangebyscore salary -inf +inf #显示整个有序集
1) "hyd"
2) "lmp"
3) "wyt"
127.0.0.1:6379> zrangebyscore salary -inf +inf withscores #递增排列
1) "hyd"
2) "500"
3) "lmp"
4) "500"
5) "wyt"
6) "5000"127.0.0.1:6379> zrangebyscore salary -inf 2500 withscores #显示工资 <=2500的所有成员
1) "hyd"
2) "500"
3) "lmp"
4) "500"#============================
# zrem 移除有序集中的一个或多个成员
#============================
127.0.0.1:6379> zrange salary 0 -1
1) "hyd"
2) "lmp"
3) "wyt"
127.0.0.1:6379> zrem salary hyd
(integer) 1
127.0.0.1:6379> zrange salary 0 -1
1) "lmp"
2) "wyt"
#============================
# zcard 命令用于计算集合中元素的数量
#============================
127.0.0.1:6379> zcard salary
(integer) 2
#============================
# zcount 计算有序集合中指定分数区间的成员数量
#============================
127.0.0.1:6379> zadd myset 1 wyt
(integer) 1
127.0.0.1:6379> zadd myset 2 lmp 3 hyd
(integer) 2
127.0.0.1:6379> zcount myset 1 3
(integer) 3
127.0.0.1:6379> zcount myset 1 2
(integer) 2
#============================
# zrank 返回有序集合中指定成员的排名,其中有序集成员按分数值递增(从小到大)顺序排列
#============================
127.0.0.1:6379> zadd salary 2500 hyd
(integer) 1
127.0.0.1:6379> zadd salary 5000 wyt
(integer) 1
127.0.0.1:6379> zadd salary 500 lmp
(integer) 1
127.0.0.1:6379> zrange salary 0 -1 withscores #显示所有成员及其score值
1) "lmp"
2) "500"
3) "hyd"
4) "2500"
5) "wyt"
6) "5000"
127.0.0.1:6379> zrank salary wyt
(integer) 2
127.0.0.1:6379> zrank salary lmp
(integer) 0#============================
# zrevrank 返回有序集中成员的排名 其中有序集成员按分数值递减(从大到小)排序
#============================
127.0.0.1:6379> zrevrank salary lmp #lmp第三
(integer) 2
127.0.0.1:6379> zrevrank salary wyt #wyt第一
(integer) 0
总结:
边栏推荐
- 【LVGL(1)】LVGL的简单介绍
- CentOS操作系统安全加固
- Talk about strong cache and negotiation cache
- Random forest, lgbm parameter adjustment based on Bayesian Optimization
- Backup MySQL database with bat script under Windows
- 中药材的鉴别
- [esp8266 spot welder] Based on esp8266 for Arduino
- Custom MVC 2.0
- kubernetes简介(kubernetes优点)
- Experiment: disk quota operation
猜你喜欢

【LVGL(1)】LVGL的简单介绍

【波形/信号发生器】基于 STC1524K32S4 for C on Keil

xxl执行节点错误日志刷屏

Take you to understand the inventory deduction principle of MySQL database

这些坑你不掌握,你还真不敢用BigDecimal

NFS shared services and experiments

基于回归分析的广告投入销售额预测——K邻近,决策树,随机森林,线性回归,岭回归

实验:LVM逻辑卷的建立、扩容、与删除

Difference between PX and EM and REM

SSH远程访问及控制
随机推荐
Solution of forgetting root password in mysql5.7 under Windows
STM32基于 FatFs R0.14b&SD Card 的MP3音乐播放器(也算是FatFs的简单应用了吧)
Special effects - when the mouse moves, stars appear to trail
Jenkins CI CD
Machine learning case: smoking in pregnant women and fetal health
Several common problems of SQL server synchronization database without public IP across network segments
【LVGL(重要)】样式属性API函数及其参数
Kubernetes rapid installation
CentOS operating system security reinforcement
HashSet转数组
Breadth first search (template use)
You don't know these pits. You really don't dare to use BigDecimal
DHCP原理与配置
xxl执行节点错误日志刷屏
Account and authority management
【音频解码芯片】VS1503音频解码芯片的应用
Go environment construction and start
kubernetes急速安装
Special effects - click with the mouse and the fireworks will burst
基于回归分析的广告投入销售额预测——K邻近,决策树,随机森林,线性回归,岭回归