解释:移除有续集中指定排名范围【start stop】的元素,返回移除元素个数
[plain] view plaincopyprint? 01.redis 127.0.0.1:6379> zrange score 0 -1 02.1) "zhangsan" 03.2) "lisi" 04.3) "wangwu" 05.4) "liuli" 06.redis 127.0.0.1:6379> zremrangebyrank score 0 1 07.(integer) 2 08.redis 127.0.0.1:6379> zrange score 0 -1 09.1) "wangwu" 10.2) "liuli" redis 127.0.0.1:6379> zrange score 0 -1 1) "zhangsan" 2) "lisi" 3) "wangwu" 4) "liuli" redis 127.0.0.1:6379> zremrangebyrank score 0 1 (integer) 2 redis 127.0.0.1:6379> zrange score 0 -1 1) "wangwu" 2) "liuli" 注意:如果stop在start之前,则移除0个
c)zremrangebyscore
语法:zremrangebyscore key min max
解释:移除有续集中的member,移除member的score大于等于min小于等于max;返回移除元素个数
[plain] view plaincopyprint? 01.redis 127.0.0.1:6379> zrange score 0 -1 withscores 02.1) "wangwu" 03.2) "249" 04.3) "liuli" 05.4) "400" 06.redis 127.0.0.1:6379> zremrangebyscore score 248 250 07.(integer) 1 08.redis 127.0.0.1:6379> zrange score 0 -1 withscores 09.1) "liuli" 10.2) "400" redis 127.0.0.1:6379> zrange score 0 -1 withscores 1) "wangwu" 2) "249" 3) "liuli" 4) "400" redis 127.0.0.1:6379> zremrangebyscore score 248 250 (integer) 1 redis 127.0.0.1:6379> zrange score 0 -1 withscores 1) "liuli" 2) "400" 5)其他
a)zinterstore
语法:zinterstore destination numkeys key[key...] [weights weight] [aggregate sum|min|max]
解释:统计多个有续集的交集,其中有续集key的个数必须以numkeys参数指定,并将统计结果存储到destination。默认情况下,destination中元素的score是各个有续集key中元素的score之和。使用weights为每个有续集指定个乘法因子,每个有续集的score在传递给集合函数(aggregate)之前,先乘以乘法因子。如果没指定乘法因子weight,默认是1;使用aggregate选项指定交集的聚合方式。min,最小score,max,最大score,sum,求和。
[plain] view plaincopyprint? 01.redis 127.0.0.1:6379> zrange score 0 -1 withscores 02.1) "lisi" 03.2) "20" 04.3) "liuli" 05.4) "400" 06.redis 127.0.0.1:6379> zrange score1 0 -1 withscores 07.1) "wangwu" 08.2) "20" 09.3) "liuli" 10.4) "30" 11.redis 127.0.0.1:6379> zinterstore dest 2 score score1 #交集求和 sum(score.member.score * 1 + score1.member.score * 1) 12.(integer) 1 13.redis 127.0.0.1:6379> zrange dest 0 -1 withscores 14.1) "liuli" 15.2) "430" 16.redis 127.0.0.1:6379> zinterstore dest 2 score score1 weights 1 2 #交集求和,sum(score.member.score * 1 + score1.member.score * 2) 17.(integer) 1 18.redis 127.0.0.1:6379> zrange dest 0 -1 withscores 19.1) "liuli" 20.2) "460" 21.redis 127.0.0.1:6379> zinterstore dest 2 score score1 aggregate min #交集求最小值,min(score.member.score * 1 , score1.member.score * 1) 22.(integer) 1 23.redis 127.0.0.1:6379> zrange dest 0 -1 withscores 24.1) "liuli" 25.2) "30" 26.redis 127.0.0.1:6379> zinterstore dest 2 score score1 aggregate max #交集求最大值 max(score.member.score * 1 , score1.member.score * 1) 27.(integer) 1 28.redis 127.0.0.1:6379> zrange dest 0 -1 withscores 29.1) "liuli" 30.2) "400" 31.redis 127.0.0.1:6379> zinterstore dest 2 score score1 aggregate sum #交集求和,sum(score.member.score * 1 , score1.member.score * 1) 32.(integer) 1 33.redis 127.0.0.1:6379> zrange dest 0 -1 withscores 34.1) "liuli" 35.2) "430" 36.redis 127.0.0.1:6379> zinterstore dest 2 score score1 weights 1 2 aggregate min #交集求最小值 min(score.member.score * 1 , score1.member.score * 2) 37.(integer) 1 38.redis 127.0.0.1:6379> zrange dest 0 -1 withscores 39.1) "liuli" 40.2) "60" redis 127.0.0.1:6379> zrange score 0 -1 withscores 1) "lisi" 2) "20" 3) "liuli" 4) "400" redis 127.0.0.1:6379> zrange score1 0 -1 withscores 1) "wangwu" 2) "20" 3) "liuli" 4) "30" redis 127.0.0.1:6379> zinterstore dest 2 score score1 #交集求和 sum(score.member.score * 1 + score1.member.score * 1) (integer) 1 redis 127.0.0.1:6379> zrange dest 0 -1 withscores 1) "liuli" 2) "430" redis 127.0.0.1:6379> zinterstore dest 2 score score1 weights 1 2 #交集求和,sum(score.member.score * 1 + score1.member.score * 2) (integer) 1 redis 127.0.0.1:6379> zrange dest 0 -1 withscores 1) "liuli" 2) "460" redis 127.0.0.1:6379> zinterstore dest 2 score score1 aggregate min #交集求最小值,min(score.member.score * 1 , score1.member.score * 1) (integer) 1 redis 127.0.0.1:6379> zrange dest 0 -1 withscores 1) "liuli" 2) "30" redis 127.0.0.1:6379> zinterstore dest 2 score score1 aggregate max #交集求最大值 max(score.member.score * 1 , score1.member.score * 1) (integer) 1 redis 127.0.0.1:6379> zrange dest 0 -1 withscores 1) "liuli" 2) "400" redis 127.0.0.1:6379> zinterstore dest 2 score score1 aggregate sum #交集求和,sum(score.member.score * 1 , score1.member.score * 1) (integer) 1 redis 127.0.0.1:6379> zrange dest 0 -1 withscores 1) "liuli" 2) "430" redis 127.0.0.1:6379> zinterstore dest 2 score score1 weights 1 2 aggregate min #交集求最小值 min(score.member.score * 1 , score1.member.score * 2) (integer) 1 redis 127.0.0.1:6379> zrange dest 0 -1 withscores 1) "liuli" 2) "60"
b)zunionstore
语法:zunionstore destination numkeys key[key...] [weights weight] [aggregate sum|min|max]
解释:统计多个有续集的并集,其中有续集key的个数必须以numkeys参数指定,并将统计结果存储到destination。。默认情况下,destination中元素的score是各个有续集key中元素的score之和。weights指定乘法因子,aggregate指定聚合方式,详情,请参阅 zinterstore 中介绍
[plain] view plaincopyprint? 01.redis 127.0.0.1:6379> zrange score 0 -1 withscores 02.1) "lisi" 03.2) "20" 04.3) "liuli" 05.4) "400" 06.redis 127.0.0.1:6379> zrange score1 0 -1 withscores 07.1) "wangwu" 08.2) "20" 09.3) "liuli" 10.4) "30" 11.redis 127.0.0.1:6379> zunionstore dest 2 score score1 #交集求和 sum(score.member.score * 1 , score1.member.score * 1) 12.(integer) 3 13.redis 127.0.0.1:6379> zrange dest 0 -1 withscores 14.1) "lisi" 15.2) "20" 16.3) "wangwu" 17.4) "20" 18.5) "liuli" 19.6) "430" 20.redis 127.0.0.1:6379> zunionstore dest 2 score score1 weights 1 2 aggregate sum #交集求和 sum(score.member.score * 1 , score1.member.score * 2) 21.(integer) 3 22.redis 127.0.0.1:6379> zrange dest 0 -1 withscores 23.1) "lisi" 24.2) "20" 25.3) "wangwu" 26.4) "40" 27.5) "liuli" 28.6) "460" 29.redis 127.0.0.1:6379> zunionstore dest 2 score score1 weights 1 2 aggregate max #交集最大值 max(score.member.score * 1 , score1.member.score * 2) 30.(integer) 3 31.redis 127.0.0.1:6379> zrange dest 0 -1 withscores 32.1) "lisi" 33.2) "20" 34.3) "wangwu" 35.4) "40" 36.5) "liuli" 37.6) "400" 38.redis 127.0.0.1:6379> zunionstore dest 2 score score1 weights 2 4 aggregate min #交集最小值 min(score.member.score * 2 , score1.member.score * 4) 39.(integer) 3 40.redis 127.0.0.1:6379> zrange dest 0 -1 withscores 41.1) "lisi" 42.2) "40" 43.3) "wangwu" 44.4) "80" 45.5) "liuli" 46.6) "120" redis 127.0.0.1:6379> zrange score 0 -1 withscores 1) "lisi" 2) "20" 3) "liuli" 4) "400" redis 127.0.0.1:6379> zrange score1 0 -1 withscores 1) "wangwu" 2) "20" 3) "liuli" 4) "30" redis 127.0.0.1:6379> zunionstore dest 2 score score1 #交集求和 sum(score.member.score * 1 , score1.member.score * 1) (integer) 3 redis 127.0.0.1:6379> zrange dest 0 -1 withscores 1) "lisi" 2) "20" 3) "wangwu" 4) "20" 5) "liuli" 6) "430" redis 127.0.0.1:6379> zunionstore dest 2 score score1 weights 1 2 aggregate sum #交集求和 sum(score.member.score * 1 , score1.member.score * 2) (integer) 3 redis 127.0.0.1:6379> zrange dest 0 -1 withscores 1) "lisi" 2) "20" 3) "wangwu" 4) "40" 5) "liuli" 6) "460" redis 127.0.0.1:6379> zunionstore dest 2 score score1 weights 1 2 aggregate max #交集最大值 max(score.member.score * 1 , score1.member.score * 2) (integer) 3 redis 127.0.0.1:6379> zrange dest 0 -1 withscores 1) "lisi" 2) "20" 3) "wangwu" 4) "40" 5) "liuli" 6) "400" redis 127.0.0.1:6379> zunionstore dest 2 score score1 weights 2 4 aggregate min #交集最小值 min(score.member.score * 2 , score1.member.score * 4) (integer) 3 redis 127.0.0.1:6379> zrange dest 0 -1 withscores 1) "lisi" 2) "40" 3) "wangwu" 4) "80" 5) "liuli" 6) "120"
提醒:sorted set的所有函数,请用下面方式查看
[plain] view plaincopyprint? 01.[root@xsf001 ~]# redis-cli 02.redis 127.0.0.1:6379> help @sorted_set
上一页 [1] [2]
|