描述:keys对应的numkeys个有序集合计算合集,并将结果存储在destination中
参数:keyOutput arrayZSetKeys arrayWeights aggregateFunction
返回值:并集数组
26,zinter
描述:keys对应的numkeys个有序集合计算交集,并将结果存储在destination中
参数:keyOutput arrayZSetKeys arrayWeights aggregateFunction
返回值:交集数组
13-26的代码例子:
复制代码 代码如下:
$redis = new redis();
$redis->connect('192.168.1.108', 6379);
$redis->delete('test');
$redis->zadd('test', 1, 'val1');
$redis->zadd('test', 0, 'val2');
$redis->zadd('test', 3, 'val3');
print_r($redis->zrange('test', 0, -1)); //结果:Array ( [0] => val2 [1] => val1 [2] => val3 )
$redis->zdelete('test', 'val2');
print_r($redis->zrange('test', 0, -1)); //结果:Array ( [0] => val1 [1] => val3 )
$redis->zadd('test',4, 'val0');
print_r($redis->zrevrange('test', 0, -1)); //结果:Array ( [0] => val0 [1] => val3 [2] => val1 )
print_r($redis->zrevrange('test', 0, -1,true)); //结果:Array ( [val0] => 4 [val3] => 3 [val1] => 1 )
echo "<br>";
$redis->zadd('key', 0, 'val0');
$redis->zadd('key', 2, 'val2');
$redis->zadd('key', 10, 'val10');
print_r($redis->zrangebyscore('key', 0, 3, array('limit' => array(1, 1),'withscores' => TRUE))); //结果:Array ( [val2] => 2 )
print_r($redis->zrangebyscore('key', 0, 3, array('limit' => array(1, 1)))); //结果:Array ( [0] => val2 )
echo $redis->zcount('key', 0, 3); //结果:2
$redis->zremrangebyscore('key', 0, 3);
print_r($redis->zrange('key', 0, -1)); //结果:Array ( [0] => val10 )
echo $redis->zsize('key'); //结果:1
$redis->zadd('key', 2.5, 'aaaa');
echo $redis->zscore('key', 'aaaa'); //结果:2.5
echo $redis->zrank('key', 'aaaa'); //结果:0
echo $redis->zrevrank('key', 'aaaa'); //结果:1
$redis->delete('key');
echo $redis->zincrby('key', 2, 'aaaa'); //结果:2
echo $redis->zincrby('key', 1, 'aaaa'); //结果:3
$redis->delete('key');
$redis->delete('test');
$redis->zadd('key', 0, 'val0');
$redis->zadd('key', 1, 'val1');
$redis->zadd('key', 4, 'val2');
$redis->zadd('test', 2, 'val2');
$redis->zadd('test', 3, 'val3');
$redis->zunion('k01', array('key', 'test'));
print_r($redis->zrange('k01',0, -1)); //结果:Array ( [0] => val0 [1] => val1 [2] => val3 [3] => val2 )
$redis->zunion('k03', array('key', 'test'), array(5, 1));
print_r($redis->zrange('k03',0, -1)); //结果:Array ( [0] => val0 [1] => val3 [2] => val1 [3] => val2 )
$redis->zinter('k02', array('key', 'test'));
print_r($redis->zrange('k02',0, -1)); //结果:Array ( [0] => val2 )
?>
您可能感兴趣的文章: