-
-
Notifications
You must be signed in to change notification settings - Fork 996
Description
Describe the bug
GEOSEARCH
is not flagged as a read-only command in the Predis library, causing the client to incorrectly switch to the master node for this operation, even though GEOSEARCH
should be treated as a read command. This behavior occurs because GEOSEARCH
is missing from Predis's internal list of read-only commands, leading to incorrect role transitions between master and replica nodes.
To Reproduce
Steps to reproduce the behavior:
- Configure a Redis sentinel environment with one master and 3 replicas.
- Call a
GEOSEARCH
command. - Notice that the
GEOSEARCH
command is executed on the master node instead of the replica. - All subsequent commands are executed on replicas.
- Observe the connection role changes back to "master" after the
GEOSEARCH
command, instead of staying on "slave."
Expected behavior
Since GEOSEARCH
is a read-only command, the connection role should remain as "slave" throughout the entire process. The expected output should be:
string(6) "slave"
string(5) "slave"
string(6) "slave"
Versions (please complete the following information):
- Predis: 2.2.2
- PHP: 8.3
- Valkey Server: 8.0
- OS: Alma 9
Code sample
$c = new Predis\Client(
[$server],
new \Predis\Configuration\Options(
[
'replication' => 'sentinel',
'service' => 'mymaster'
]
)
);
$con = $c->getConnection();
$c->geosearch(
'key_1',
new \Predis\Command\Argument\Geospatial\FromLonLat(23.591423, 46.771210),
new \Predis\Command\Argument\Geospatial\ByRadius(1000, 'm')
);
$current = $con->getCurrent()->getParameters();
var_dump($current->role); // Outputs "master", should be slave
$con->disconnect();
if ($con instanceof \Predis\Connection\Replication\ReplicationInterface) {
$con->switchToSlave();
}
$c->zrange('key_1', 0, 1);
$current = $con->getCurrent()->getParameters();
var_dump($current->role); // Outputs "slave"
$c->geosearch(
'key_1',
new \Predis\Command\Argument\Geospatial\FromLonLat(23.591423, 46.771210),
new \Predis\Command\Argument\Geospatial\ByRadius(1000, 'm')
);
$current = $con->getCurrent()->getParameters();
var_dump($current->role); // Outputs "master" again
Additional context
This behavior occurs because the GEOSEARCH
command is not included in Predis's list of read-only commands. Adding it to this list would allow it to be executed on the replica without forcing a switch to the master node.