Skip to content

Commit

Permalink
Merge pull request #493 from B-Galati/issue-449
Browse files Browse the repository at this point in the history
Fix #449 - No master server available for replication
  • Loading branch information
B-Galati committed Feb 5, 2019
2 parents 746a5c2 + d18468b commit fff674f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Factory/PredisParametersFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ public static function create($options, $class, $dsn)
throw new \InvalidArgumentException(sprintf('%s::%s requires $class argument to implement %s', __CLASS__, __METHOD__, '\Predis\Connection\ParametersInterface'));
}

$defaultOptions = array('timeout' => null); // Allow to be consistent with old version of Predis where default timeout was 5
$dsnOptions = static::parseDsn(new RedisDsn($dsn));
$dsnOptions = array_merge($options, $dsnOptions);
$dsnOptions = array_merge($defaultOptions, $options, $dsnOptions);

if (isset($dsnOptions['persistent'], $dsnOptions['database']) && true === $dsnOptions['persistent']) {
$dsnOptions['persistent'] = (int)$dsnOptions['database'];
Expand All @@ -48,12 +49,18 @@ private static function parseDsn(RedisDsn $dsn)
$options['path'] = $dsn->getDatabase();
}
}

if (null !== $dsn->getDatabase()) {
$options['database'] = $dsn->getDatabase();
}

$options['password'] = $dsn->getPassword();
$options['weight'] = $dsn->getWeight();

if (null !== $dsn->getAlias()) {
$options['alias'] = $dsn->getAlias();
}

return $options;
}
}
15 changes: 15 additions & 0 deletions Tests/Factory/PredisParametersFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,21 @@ public function createDp()
'port' => 6380,
'password' => 'pw'
)
),
array(
'redis://localhost?alias=master',
'Predis\Connection\Parameters',
array('replication' => true),
array(
'scheme' => 'tcp',
'host' => 'localhost',
'port' => 6379,
'replication' => true,
'password' => null,
'weight' => null,
'alias' => 'master',
'timeout' => null,
)
)
);
}
Expand Down

0 comments on commit fff674f

Please sign in to comment.