redis zinterstore zunionstore 排行交集并集

zinterstore/zunionstore destination numkeys key [key ...] [weights weight [weight ...]] [aggregate sum|min|max] 获取交集/并集
这个 API 看起来有点复杂,不要怕,一个个的讲:


zinterstore/zunionstore其实就是交集/并集
destination 将交集/并集的结果保存到这个键中
numkeys 需要做交集/并集的集合的个数
key [key ...] 具体参与交集/并集的集合
weights weight [weight ...] 每个参与计算的集合的权重。在做交集/并集计算时,每个集合中的 member 会把自己的 score 乘以这个权重,默认为 1。
aggregate sum|min|max 对于各个集合中的相同元素是 sum(求和)、min(取最小值)还是max(取最大值),默认为 sum。

评论