zinterstore


zinterstore(intersection store) 求两个集合的交集,交集的成员的score会累加,返回的是destination交集的成员元素个数

127.0.0.1:6379[1]> zrange set1 0 -1 withscores
1) "youyi"
2) "100"
3) "z"
4) "200"
127.0.0.1:6379[1]> zrange set2 0 -1 withscores
1) "g"
2) "200"
3) "youyi"
4) "200"
127.0.0.1:6379[1]> zrange set3 0 -1 withscores
1) "d"
2) "200"
3) "youyi"
4) "200"
127.0.0.1:6379[1]> zinterstore destination 2 set1 set2
(integer) 1
127.0.0.1:6379[1]> zrange destination 0 -1 withscores
1) "youyi"
2) "300" #score累加之后为300
------------------------------------------------------
127.0.0.1:6379[1]> zrange set1 0 -1 withscores
1) "youyi"
2) "100"
3) "z"
4) "200"
127.0.0.1:6379[1]> zrange set2 0 -1 withscores
1) "g"
2) "200"
3) "youyi"
4) "200"
127.0.0.1:6379[1]> zrange set3 0 -1 withscores
1) "d"
2) "200"
3) "youyi"
4) "200"
127.0.0.1:6379[1]> zinterstore destination 3 set1 set2 set3
(integer) 1
127.0.0.1:6379[1]> zrange destination 0 -1 withscores
1) "youyi"
2) "500"#score累加之后为500

results matching ""

    No results matching ""