php redis zinter,zInter 命令/方法/函数

本文详细介绍了Redis中的ZINTERSTORE命令,用于计算多个有序集合的交集,并将结果存储到新的有序集合中。内容涵盖了命令的使用方法、参数解释、权重和聚合选项的应用,以及具体的示例操作,展示了如何通过权重调整和不同聚合方式改变交集结果。
摘要由CSDN通过智能技术生成

Creates an intersection of sorted sets given in second argument. The result of the union will be stored in the sorted set defined by the first argument. The third optionnel argument defines weights to apply to the sorted sets in input. In this case, the weights will be multiplied by the score of each element in the sorted set before applying the aggregation. The forth argument defines the AGGREGATEoption which specify how the results of the union are aggregated.

计算numkeys个由keys指定的有序集合的交集,并且将结果存储在destination中。在该命令中,在你传递输入keys之前,必须提供输入keys的个数和其它可选的参数。

在默认情况下,一个元素的结果score是具有该元素的所有有序集合的score的和。关于WEIGHTS和AGGREGATE选项,可以参看ZUNIONSTORE命令。如果目标已经存在,那么它将会被重写。

Parameters

keyOutput

arrayZSetKeys

arrayWeights

aggregateFunction Either "SUM", "MIN", or "MAX": defines the behaviour to use on duplicate entries during the zInter.

Return value

LONG The number of values in the new sorted set.

Example

$redis->delete('k1');

$redis->delete('k2');

$redis->delete('k3');

$redis->delete('ko1');

$redis->delete('ko2');

$redis->delete('ko3');

$redis->delete('ko4');

$redis->zAdd('k1', 0, 'val0');

$redis->zAdd('k1', 1, 'val1');

$redis->zAdd('k1', 3, 'val3');

$redis->zAdd('k2', 2, 'val1');

$redis->zAdd('k2', 3, 'val3');

$redis->zInter('ko1', array('k1', 'k2'));               /* 2, 'ko1' => array('val1', 'val3') */

$redis->zInter('ko2', array('k1', 'k2'), array(1, 1));  /* 2, 'ko2' => array('val1', 'val3') */

/* Weighted zInter */

$redis->zInter('ko3', array('k1', 'k2'), array(1, 5), 'min'); /* 2, 'ko3' => array('val1', 'val3') */

$redis->zInter('ko4', array('k1', 'k2'), array(1, 5), 'max'); /* 2, 'ko4' => array('val3', 'val1') */

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值