mirror of
https://github.com/predis/predis.git
synced 2026-08-19 00:51:56 +00:00
Fix parameters overriding for sentinels.
Different fix than PR #339 but thanks @phofmann-trust for spotting.
This commit is contained in:
@@ -239,14 +239,13 @@ class SentinelReplication implements ReplicationInterface
|
||||
}
|
||||
|
||||
if (is_array($parameters)) {
|
||||
$parameters += array(
|
||||
'timeout' => $this->sentinelTimeout,
|
||||
// We unset "password" and "database" from user-supplied parameters
|
||||
// as they are not needed when connecting to sentinels.
|
||||
unset($parameters['database'], $parameters['password']);
|
||||
|
||||
// We need to override password and database by setting them to
|
||||
// NULL as they are not needed when connecting to sentinels.
|
||||
'password' => null,
|
||||
'database' => null,
|
||||
);
|
||||
if (!isset($parameters['timeout'])) {
|
||||
$parameters['timeout'] = $this->sentinelTimeout;
|
||||
}
|
||||
}
|
||||
|
||||
$connection = $this->connectionFactory->create($parameters);
|
||||
|
||||
@@ -33,6 +33,69 @@ class SentinelReplicationTest extends PredisTestCase
|
||||
$replication->getSentinelConnection();
|
||||
}
|
||||
|
||||
/**
|
||||
* @group disconnected
|
||||
*/
|
||||
public function testParametersForSentinelConnectionShouldNotUseDatabaseAndPassword()
|
||||
{
|
||||
$replication = $this->getReplicationConnection('svc', array(
|
||||
'tcp://127.0.0.1:5381?alias=sentinel1&database=1&password=secret',
|
||||
));
|
||||
|
||||
$parameters = $replication->getSentinelConnection()->getParameters()->toArray();
|
||||
|
||||
$this->assertArrayNotHasKey('password', $parameters);
|
||||
$this->assertArrayNotHasKey('database', $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group disconnected
|
||||
*/
|
||||
public function testParametersForSentinelConnectionHaveDefaultTimeout()
|
||||
{
|
||||
$replication = $this->getReplicationConnection('svc', array(
|
||||
'tcp://127.0.0.1:5381?alias=sentinel',
|
||||
));
|
||||
|
||||
$parameters = $replication->getSentinelConnection()->getParameters()->toArray();
|
||||
|
||||
$this->assertArrayHasKey('timeout', $parameters);
|
||||
$this->assertSame(0.100, $parameters['timeout']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group disconnected
|
||||
*/
|
||||
public function testParametersForSentinelConnectionCanOverrideDefaultTimeout()
|
||||
{
|
||||
$replication = $this->getReplicationConnection('svc', array(
|
||||
'tcp://127.0.0.1:5381?alias=sentinel&timeout=1',
|
||||
));
|
||||
|
||||
$parameters = $replication->getSentinelConnection()->getParameters()->toArray();
|
||||
|
||||
$this->assertArrayHasKey('timeout', $parameters);
|
||||
$this->assertSame('1', $parameters['timeout']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group disconnected
|
||||
*/
|
||||
public function testConnectionParametersInstanceForSentinelConnectionIsNotModified()
|
||||
{
|
||||
$originalParameters = Connection\Parameters::create(
|
||||
'tcp://127.0.0.1:5381?alias=sentinel1&database=1&password=secret'
|
||||
);
|
||||
|
||||
$replication = $this->getReplicationConnection('svc', array($originalParameters));
|
||||
|
||||
$parameters = $replication->getSentinelConnection()->getParameters();
|
||||
|
||||
$this->assertSame($originalParameters, $parameters);
|
||||
$this->assertNotNull($parameters->password);
|
||||
$this->assertNotNull($parameters->database);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group disconnected
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user