Fix the echo liveness check when in sentinel mode.

The current echo liveness check was doing one big complex conditional
trying to incorporate both sentinel's expected ERR no such command
response and non-sentinel's actual bulk reply to ECHO.

This commit refactors the logic to check the echo response into a little
helper with different logic depending on whether or not we're connected
to a sentinel.

Additionally, we add a test to verify that we are in fact reusing
persistent connections when the user requests a persistent connection
with `RedisSentinel`.

Fixes #2148
This commit is contained in:
michael-grunder
2025-07-16 22:14:12 -07:00
committed by Michael Grunder
parent 75acbb0984
commit 2acab399cb
2 changed files with 64 additions and 11 deletions
+41
View File
@@ -116,4 +116,45 @@ class Redis_Sentinel_Test extends TestSuite
$this->checkFields($slave);
}
}
protected function getClients(Redis $redis, string $cmd)
{
$result = [];
foreach ($redis->client('list') as $client) {
if ($client['cmd'] !== $cmd)
continue;
$result[] = $client['id'];
}
return $result;
}
public function testPersistent() {
/* I think the tests just use the default port */
$redis = new Redis;
$redis->connect($this->getHost(), 26379);
$id = null;
for ($i = 0; $i < 3; $i++) {
$sentinel = new RedisSentinel([
'host' => $this->getHost(),
'persistent' => 'sentinel',
]);
$this->assertTrue($sentinel->ping());
$clients = $this->getClients($redis, 'ping');
/* Capture the ping client */
$id ??= $clients[0];
unset($sentinel);
}
/* The same client should have been reused */
$this->assertEquals($id, $clients[0]);
}
}