标签:with 指定元素 利用 redis top n inf rgb 一个 命令
在set的基础上,增加了一个值,set k1 v1 zset k1 score v1
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>
127.0.0.1:6379> zrange myset 0 -1 1) "one" 2) "two" 3) "three" 127.0.0.1:6379>
127.0.0.1:6379> zadd salary 2500 xiaohong (integer) 1 127.0.0.1:6379> zadd salary 5000 zhangsan (integer) 1 127.0.0.1:6379> zadd salary 500 ckfuture (integer) 1 127.0.0.1:6379> zrangebyscore salary -inf +inf 1) "ckfuture" 2) "xiaohong" 3) "zhangsan" 127.0.0.1:6379>
-inf:负无穷
+inf:正无穷
127.0.0.1:6379> zrangebyscore salary -inf +inf withscores
1) "ckfuture"
2) "500"
3) "xiaohong"
4) "2500"
5) "zhangsan"
6) "5000"
127.0.0.1:6379>
127.0.0.1:6379> zrem salary xiaohong
(integer) 1
127.0.0.1:6379>
127.0.0.1:6379> zcard salary
(integer) 2
127.0.0.1:6379>
127.0.0.1:6379> zrevrange salary 0 -1 withscores
1) "zhangsan"
2) "5000"
3) "ckfuture"
4) "500"
127.0.0.1:6379>
127.0.0.1:6379> zcount myset 1 3
(integer) 6
存储班级成绩、工资表,
带权重进行判断:例如:普通消息 1,重要消息2
排行榜应用实现:top n 测试
标签:with 指定元素 利用 redis top n inf rgb 一个 命令
原文地址:https://www.cnblogs.com/ckfuture/p/14395749.html