sUnionStore 命令/方法/函数

Performs the same action as sUnion, but stores the result in the first key

执行一个并集操作就和sUnion()一样,但是结果储存在第一个参数中。


Parameters

Key: dstkey, the key to store the diff into.

存储结果的SET集合KEY


Keys: key1, key2, ... , keyN: Any number of keys corresponding to sets in redis.

求并集的KEYS


Return value

INTEGER: The cardinality of the resulting set, or FALSE in case of a missing key.

返回整数值:并集结果的个数。


Example

$redis->delete('s0', 's1', 's2');


$redis->sAdd('s0', '1');

$redis->sAdd('s0', '2');

$redis->sAdd('s1', '3');

$redis->sAdd('s1', '1');

$redis->sAdd('s2', '3');

$redis->sAdd('s2', '4');


var_dump($redis->sUnionStore('dst', 's0', 's1', 's2'));

var_dump($redis->sMembers('dst'));


Return value: the number of elements that are either in s0 or in s1 or in s2.

int(4)

array(4) {

  [0]=>

  string(1) "3"

  [1]=>

  string(1) "4"

  [2]=>

  string(1) "1"

  [3]=>

  string(1) "2"

}