Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[BUG] eval command with RedisCluster::FAILOVER_DISTRIBUTE_SLAVES option will throw exception #1142

@Barbery

Description

@Barbery

Info:
phpredis: lastest develop branch
redis-server: 3.2.1 and 3.0.7
system: ubuntu-14.04 64bit

If I use RedisCluster::FAILOVER_DISTRIBUTE option, that all is fine. But if I use RedisCluster::FAILOVER_DISTRIBUTE_SLAVES option, it will throw exception:

"Timed out attempting to find data in the correct node!"

Here is the example code, you can test it.

<?php
$servers = [
    '192.168.10.10:6383',
    '192.168.10.10:6384',
    '192.168.10.10:6385',
];
$readTimeout  = $timeout  = 3;
$persistent   = false;
$RedisCluster = new RedisCluster(null, $servers, $readTimeout, $timeout, $persistent);
$RedisCluster->setOption(RedisCluster::OPT_SLAVE_FAILOVER, RedisCluster::FAILOVER_DISTRIBUTE_SLAVES);
$lua = <<<'LUA'
local isSuccess = 1
local offset = 0
for i = 1, #KEYS, 1 do
    redis.call('setnx', KEYS[i], ARGV[i+offset+1])
    if redis.call('incrby', KEYS[i], math.abs(ARGV[i+offset])) > tonumber(ARGV[i+offset+2]) then
        isSuccess = 0
        break
    end
    offset = offset + 2
end

return isSuccess;
LUA;

for ($i = 0; $i < 100; $i++) {
    $RedisCluster->get($i);
    // if run the below code, all is fine
    // $RedisCluster->set($i, $i); 
}

try {
    $keys = ['counter:product:{1}:test'];
    $argv = [1, 10, 99];
    var_dump($RedisCluster->eval($lua, array_merge($keys, $argv), count($keys)));
} catch (Exception $e) {
    echo $e->getMessage();
}

Metadata

Metadata

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions