Hi,
We've been using this module successfully in production for a few years, but lately started having problems with performance in our Redis cluster (we're using Elasticache).

We're using Cluster Disabled and would like to use a node replica to alleviate load.

Looking at the docs it's not completely clear to me how we can achieve this.

Using PHPRedis

We're currently using PHPRedis and ideally we'd like to keep doing so, however, the replication examples in the README don't seem to apply to it. Is that supported? If so, how do I achieve this?

Using Predis

Assuming it's not possible to keep using PHPRedis, we'd need to transition to Predis, although it says it's experimental still. How successfully is this being used in production systems?

For testing purposes I setup some replica nodes in a staging environment and tried to configure things as per README docs, like so:

$settings['redis.connection']['interface'] = 'Predis'; // Use predis library.
$settings['redis.connection']['replication'] = TRUE; // Turns on replication.
$settings['redis.connection']['replication.host'][1]['host'] = '1.2.3.4';  // Your Redis instance hostname.
$settings['redis.connection']['replication.host'][1]['port'] = '6379'; // Only required if using non-standard port.
$settings['redis.connection']['replication.host'][1]['role'] = 'primary'; // The redis instance role.
$settings['redis.connection']['replication.host'][2]['host'] = '1.2.3.5';
$settings['redis.connection']['replication.host'][2]['port'] = '6379';
$settings['redis.connection']['replication.host'][2]['role'] = 'replica';

However, when I do this I get the following error:

InvalidArgumentException: Predis\Configuration\Option\Replication expects either a string or a callable value, boolean given in Predis\Configuration\Option\Replication->filter() (line 40 of /var/www/html/vendor/predis/predis/src/Configuration/Option/Replication.php).

Debugging this, it seems like a string is expected (for the replication flag), but in the README we're passing a boolean. If I change the paremeter to be a string "true" however, then that breaks in the Drupal's Redis implementation, specifically here in ClientFactory:

      // If using replication, lets create the client appropriately.
      if (isset($settings['replication']) && $settings['replication'] === TRUE) {
        foreach ($settings['replication.host'] as $key => $replicationHost) {
          if (!isset($replicationHost['port'])) {
            $settings['replication.host'][$key]['port'] = self::REDIS_DEFAULT_PORT;
          }
        }

Can someone assist me with this one?

Thanks in advance!

Comments

kyuubi created an issue. See original summary.

yi_jiang’s picture

StatusFileSize
new5.86 KB

Hi It has been for a while, I totally forgot how I did last time, this is my original patch, see if it helps you.

kyuubi’s picture

Thanks @yi_jiang,
However this seems to be for Predis. That seems to be slower and less supported.
I'm interested in a solution using PhpRedis.

juanl’s picture

StatusFileSize
new1.49 KB

in case this helps someone, the attached patch enable replication.
Status detail page only show master role, it should be extended to the replicas as well.

juanl’s picture

StatusFileSize
new5.17 KB
juanl’s picture

StatusFileSize
new1.21 KB
firewaller’s picture

Status: Active » Reviewed & tested by the community

#6 works for me

  • berdir committed 5437c817 on 8.x-1.x
    Issue #3317492 by juanl, yi_jiang: Options available for replication (...
berdir’s picture

Status: Reviewed & tested by the community » Fixed

Committed.

  • berdir committed 69aab13d on 8.x-1.x
    Revert "Issue #3317492 by juanl, yi_jiang: Options available for...
berdir’s picture

Status: Fixed » Needs work

Had to revert this, breaks the status report page when not using replication as new tests demonstrated:

InvalidArgumentException: Selecting connection by role is not supported by Predis\Connection\StreamConnection in Predis\Client->getClientBy() (line 216 of /builds/project/redis/vendor/predis/predis/src/Client.php).