From ce8b3fb683f7043896010e274e10adc73b80e4a4 Mon Sep 17 00:00:00 2001 From: Pascal Hofmann Date: Tue, 14 Jun 2016 16:18:59 +0200 Subject: [PATCH] Don't send AUTH and/or SELECT command after connecting to sentinels --- src/Connection/Replication/SentinelReplication.php | 7 ++++--- .../Connection/Replication/SentinelReplicationTest.php | 3 +-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Connection/Replication/SentinelReplication.php b/src/Connection/Replication/SentinelReplication.php index 60042022..20d7e91f 100644 --- a/src/Connection/Replication/SentinelReplication.php +++ b/src/Connection/Replication/SentinelReplication.php @@ -239,9 +239,10 @@ class SentinelReplication implements ReplicationInterface } if (is_array($parameters)) { - // We unset "password" and "database" from user-supplied parameters - // as they are not needed when connecting to sentinels. - unset($parameters['database'], $parameters['password']); + // We explicitly set "database" and "password" to null, + // so that no AUTH and SELECT command is send to the sentinels. + $parameters['database'] = null; + $parameters['password'] = null; if (!isset($parameters['timeout'])) { $parameters['timeout'] = $this->sentinelTimeout; diff --git a/tests/Predis/Connection/Replication/SentinelReplicationTest.php b/tests/Predis/Connection/Replication/SentinelReplicationTest.php index 5e4eb630..752c636d 100644 --- a/tests/Predis/Connection/Replication/SentinelReplicationTest.php +++ b/tests/Predis/Connection/Replication/SentinelReplicationTest.php @@ -44,8 +44,7 @@ class SentinelReplicationTest extends PredisTestCase $parameters = $replication->getSentinelConnection()->getParameters()->toArray(); - $this->assertArrayNotHasKey('password', $parameters); - $this->assertArrayNotHasKey('database', $parameters); + $this->assertArraySubset(array('database' => null, 'password' => null), $parameters); } /**