避免使用 eval,或者迭代地调用 2 个
效果大概像这样:
function unionSets($redis, $keys)
{
if (!is_array($keys)) {
return [];
}
$count = count($keys);
$ret = [];
switch ($count)
{
case 2:
$ret = $redis->sUnion($keys[0], $keys[1]);
break;
case 3:
$ret = $redis->sUnion($keys[0], $keys[1], $keys[2]);
break;
case 4:
$ret = $redis->sUnion($keys[0], $keys[1], $keys[2], $keys[3]);
break;
case 5:
$ret = $redis->sUnion($keys[0], $keys[1], $keys[2], $keys[3], $keys[4]);
break;
case 6:
$ret = $redis->sUnion($keys[0], $keys[1], $keys[2], $keys[3], $keys[4], $keys[5]);
break;
case 7:
$ret = $redis->sUnion($keys[0], $keys[1], $keys[2], $keys[3], $keys[4], $keys[5], $keys[6]);
break;
case 8:
$ret = $redis->sUnion($keys[0], $keys[1], $keys[2], $keys[3], $keys[4], $keys[5], $keys[6], $keys[7]);
break;
case 9:
$ret = $redis->sUnion($keys[0], $keys[1], $keys[2], $keys[3], $keys[4], $keys[5], $keys[6], $keys[8], $keys[8]);
break;
default:
$ret = $redis->sUnion($keys[0], $keys[1]);
break;
}
return $ret;
}
1
echodone 2018-11-02 10:17:47 +08:00
func_get_args()、func_get_arg()与 func_num_args(),研究下这几个函数就可以了
|
3
suit 2018-11-02 10:57:10 +08:00
$redis->sUnion(...$keys);
call_user_func_array([$redis, 'sUnion'], $keys); |