Redis的Zset

常用命令

127.0.0.1:6379> zadd topn 100 java 300 c++ 400 mysql 500 php ##添加数据
(integer) 4
127.0.0.1:6379> zrange topn 0 -1##按照顺序取出全部数据
1) "java"
2) "c++"
3) "mysql"
4) "php"
-------------------------------------------------------------------
127.0.0.1:6379> zrange topn 0 -1 withscores##按照顺序取出全部数据和scores
1) "java"
2) "100"
3) "c++"
4) "300"
5) "mysql"
6) "400"
7) "php"
8) "500"
127.0.0.1:6379> 
--------------------------------------------------------------------
127.0.0.1:6379> zrangebyscore topn 300 500##按照score的范围取值
1) "c++"
2) "mysql"
3) "php"
127.0.0.1:6379>
127.0.0.1:6379> zrangebyscore topn 300 500 withscores##按照score的范围取值和scores
1) "c++"
2) "300"
3) "mysql"
4) "400"
5) "php"
6) "500"
127.0.0.1:6379> 
-------------------------------------------------------------------------------------
127.0.0.1:6379> zrevrangebyscore topn 500 300 withscores##顺序 反过来
1) "php"
2) "500"
3) "mysql"
4) "400"
5) "c++"
6) "300"
127.0.0.1:6379> 
---------------------------------------------------------------------------------------------
127.0.0.1:6379> zincrby topn 50 java##增加某个scorpe
"150"
127.0.0.1:6379> zrange topn 0 -1 withscores
1) "java"
2) "150"
3) "c++"
4) "300"
5) "mysql"
6) "400"
7) "php"
8) "500"
127.0.0.1:6379> 
-----------------------------------------------------------------------------------
127.0.0.1:6379> zrange topn 0 -1 withscores##删除某个member
1) "java"
2) "150"
3) "c++"
4) "300"
5) "mysql"
6) "400"
127.0.0.1:6379> 
-----------------------------------------------------------------
127.0.0.1:6379> zcount topn 0 500##统计score在某个范围内的元素数量
(integer) 3
127.0.0.1:6379> 
----------------------------------------------------
127.0.0.1:6379> zrank topn mysql##返回某个member的排名
(integer) 2
127.0.0.1:6379> 
-----------------------------------------------------


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值