• Resolved sebestyeng

    (@sebestyeng)


    Hi!

    I have a two-node master-slave redis system setup. If I stop the redis server on either node the Redis Object Cache plugin loses connection instead of connecting to the remaining node.

    In the scenario, I have stopped the redis on the local host. With a test Predis client, I can still connect and read from the replica but the plugin says Not connected although the other redis server (slave) is still intact.

    Error in diagnostics:

    Status: Not connected
    Client: Predis (v2.0.3)
    Drop-in: Valid
    Disabled: No
    Ping: PONG
    Errors: [
        "Connection refused [tcp:\/\/127.0.0.1:6379]"
    ]

    My related configuration in wp-config.php:

    /* REDIS CONFIGURATION */
    define( 'WP_REDIS_CLIENT', 'predis' );
    define( 'WP_REDIS_SERVERS', [
        'tcp://127.0.0.1:6379?database=0&alias=master&role=master',
        'tcp://192.168.40.105:6379?database=0&alias=replica',
    ] );
    define( 'WP_REDIS_TIMEOUT', 1 );
    define( 'WP_REDIS_READ_TIMEOUT', 1 );

    Can you please help me with this? Is this how it is supposed to work?
    My goal is to use Redis Object Cache connected to this two-node setup. If the master goes down the replica should be able to keep serving the cache.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Till Krüss

    (@tillkruess)

    Replication only reduces load when reading, so you always need the master online.

    I’d suggest reading Scaling, clustering and replication in the docs: https://redis.io/docs/management/replication/

    Thread Starter sebestyeng

    (@sebestyeng)

    Thank you for your answer!

    I read the documentation as you suggested but I don’t understand your point here. Even the title topic clearly says “How Redis supports high availability and failover with replication”.

    It is clear the master should be available, but if I stop a replica why it affects the Redis Object Cache plugin’s connection to the redis system while the master is up and ready-to-go?

    In the title of this support ticket I wrote “Not Connected if any Redis node is down“. According to this I’ve created a scenario for you where the master (127.0.0.1) is alive and the replica (192.168.40.105) goes down.

    On overview tab:

    Overview
    Status:	 Not connected
    Drop-in:	 Valid
    Filesystem:	 Writeable

    On diagnostics:

    Status: Not connected
    Client: predis
    Drop-in: Valid
    Disabled: No
    Ping: 
    Connection Exception: Connection refused [tcp://192.168.40.105:6379] (Predis\Connection\ConnectionException)
    Errors: [
        "Connection refused [tcp:\/\/192.168.40.105:6379]"
    ]

    (wp-config.php is still the same)

    I know predis client can handle this because I’ve tested it with a short PHP code.

    Plugin Author Till Krüss

    (@tillkruess)

    Can you share the Predis code that allows you to use replication with nodes down?

    Thread Starter sebestyeng

    (@sebestyeng)

    Of course. Please note that this is the very first PHP code of my life and I don’t know how to use it properly, I only tested if it can read data from my redis system with one node down.

    <?php
    require 'autoload.php';
    
    Predis\Autoloader::register();
    
    $parameters = ['tcp://192.168.40.88?role=master', 'tcp://192.168.40.105'];
    $options    = ['replication' => 'predis'];
    
    $client = new Predis\Client($parameters, $options);
    $value = $client->get('teszt');
    echo $value;
    ?>
    

    “Teszt” key is set before by redis-cli set teszt 123

    I can get it nicely:
    (I also did some telnet testing to show you that one – the replica in this case – is down)

    root@SEBILAPTOP:/tmp/predis# php client-test.php
    123
    root@SEBILAPTOP:/tmp/predis# telnet 192.168.40.105 6379
    Trying 192.168.40.105...
    telnet: Unable to connect to remote host: Connection refused
    root@SEBILAPTOP:/tmp/predis# telnet 192.168.40.88 6379
    Trying 192.168.40.88...
    Connected to 192.168.40.88.
    Escape character is '^]'.
    quit
    +OK
    Connection closed by foreign host.
    

    Plugin Author Till Krüss

    (@tillkruess)

    <?php
    require 'autoload.php';
    
    Predis\Autoloader::register();
    
    $parameters = [
        'tcp://192.168.40.88?role=master',
        'tcp://192.168.40.105?alias=replica'
    ];
    
    $options = ['replication' => 'predis'];
    
    $client = new Predis\Client($parameters, $options);
    
    var_dump($client->get('teszt'));
    var_dump($client->set('teszt', '123'));
    var_dump($client->get('teszt'));
    ?>

    Your test script only reads, it doesn’t write, can you try this script and kill of instances randomly?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Not Connected if any Redis node is down’ is closed to new replies.