8000 GEOSEARCH is read command · Issue #1480 · predis/predis · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
GEOSEARCH is read command #1480
@radu-neacsu

Description

@radu-neacsu

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:

  1. Configure a Redis sentinel environment with one master and 3 replicas.
  2. Call a GEOSEARCH command.
  3. Notice that the GEOSEARCH command is executed on the master node instead of the replica.
  4. All subsequent commands are executed on replicas.
  5. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0