zUnion 命令/方法/函数

Creates an union 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.

对keys对应的numkeys个有序集合计算合集,并将结果存储在destination中。在传递输入keys之前必须提供输入keys的个数和其它可选参数。在默认情况下,元素的结果score是包含该元素的所有有序集合中score的和。如果使用WEIGHTS选项,你可以对每一个有序集合指定一个操作因子。这意味着每一个有序集合中的每个元素的score在传递给聚合函数之前均会被乘以该因子。当WEIGHTS没有指定时,操作因子默认为1。

使用AGGREGATE选项,你可以指定交集中的结果如何被聚合。该选项默认值为SUM,在这种情况下,一个元素的所有score值均会被相加。当选项被设置为MIN或MAX时,结果集合中将会包含一个元素的最大或者最小的score值。如果destination已经存在,那么它将会被重写。


Parameters

keyOutput

arrayZSetKeys

arrayWeights

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


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->zAdd('k1', 0, 'val0');

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


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

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


$redis->zUnion('ko1', array('k1', 'k2')); /* 4, 'ko1' => array('val0', 'val1', 'val2', 'val3') */


/* Weighted zUnion */

$redis->zUnion('ko2', array('k1', 'k2'), array(1, 1)); /* 4, 'ko1' => array('val0', 'val1', 'val2', 'val3') */

$redis->zUnion('ko3', array('k1', 'k2'), array(5, 1)); /* 4, 'ko1' => array('val0', 'val2', 'val3', 'val1') */