我尝试在我的 redis-cluster 中添加一个键值对,并在一个管道中为新键设置过期。每次我收到密钥被移动的错误时,但我认为 Predis 应该遵循 MOVED 语句,就像没有流水线一样。
是不是可以在管道中进行过期调用?我正在使用 Predis 1.0.2-dev 和 redis_version: 3.0.2
这有效:
$parameters = ['tcp://10.9.200.51:47801', 'tcp://10.9.200.52:47801', 'tcp://10.9.200.53:47801', 'tcp://10.9.200.54:47801'];
$options = ['cluster' => 'redis'];
$redis = new Predis\Client($parameters, $options);
for($i = 0; $i < 10; $i++)
{
$rand = mt_rand(1111111,9999999);
$k = 'test_'.$rand;
try{
$redis->set($k, 1);
$redis->expire($k, 10);
}
catch(Exception $ex)
{
print_r($ex);
}
}
?>
这不起作用:
$parameters = ['tcp://10.9.200.51:47801', 'tcp://10.9.200.52:47801', 'tcp://10.9.200.53:47801', 'tcp://10.9.200.54:47801'];
$options = ['cluster' => 'redis'];
$redis = new Predis\Client($parameters, $options);
$pipe = $redis->pipeline();
for($i = 0; $i < 10; $i++)
{
$rand = mt_rand(1111111,9999999);
$k = 'test_'.$rand;
try{
$pipe->set($k, 1);
$pipe->expire($k, 10);
}
catch(Exception $ex)
{
print_r($ex);
}
}
$pipe->execute();
?>
我收到此错误:
PHP Fatal error: Uncaught exception 'Predis\Response\ServerException' with message 'MOVED 7276 10.9.200.61:47902' in /var/www/predis_test/Predis/Pipeline/Pipeline.php:105
Stack trace:
#0 /var/www/predis_test/Predis/Pipeline/Pipeline.php(149): Predis\Pipeline\Pipeline->exception(Object(Predis\Connection\Aggregate\RedisCluster), Object(Predis\Response\Error))
#1 /var/www/predis_test/Predis/Pipeline/Pipeline.php(168): Predis\Pipeline\Pipeline->executePipeline(Object(Predis\Connection\Aggregate\RedisCluster), Object(SplQueue))
#2 /var/www/predis_test/Predis/Pipeline/Pipeline.php(217): Predis\Pipeline\Pipeline->flushPipeline()
#3 /var/www/predis_test/lasttest.php(31): Predis\Pipeline\Pipeline->execute()
#4 {main}
thrown in /var/www/predis_test/Predis/Pipeline/Pipeline.php on line 105
编辑:似乎流水线在 redis-cluster 上不起作用。当我删除 expire 调用并且在管道中只有 set 调用时,我得到了同样的错误。