Predis\Replication\ReplicationStrategy::isReadOperation PHP Method

isReadOperation() public method

Returns if the specified command will perform a read-only operation on Redis or not.
public isReadOperation ( Predis\Command\CommandInterface $command ) : boolean
$command Predis\Command\CommandInterface Command instance.
return boolean
    public function isReadOperation(CommandInterface $command)
    {
        if (isset($this->disallowed[$id = $command->getId()])) {
            throw new NotSupportedException("The command '{$id}' is not allowed in replication mode.");
        }
        if (isset($this->readonly[$id])) {
            if (true === ($readonly = $this->readonly[$id])) {
                return true;
            }
            return call_user_func($readonly, $command);
        }
        if (($eval = $id === 'EVAL') || $id === 'EVALSHA') {
            $sha1 = $eval ? sha1($command->getArgument(0)) : $command->getArgument(0);
            if (isset($this->readonlySHA1[$sha1])) {
                if (true === ($readonly = $this->readonlySHA1[$sha1])) {
                    return true;
                }
                return call_user_func($readonly, $command);
            }
        }
        return false;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function getConnection(CommandInterface $command)
 {
     $connection = $this->getConnectionInternal($command);
     if (!$connection->isConnected()) {
         // When we do not have any available slave in the pool we can expect
         // read-only operations to hit the master server.
         $expectedRole = $this->strategy->isReadOperation($command) && $this->slaves ? 'slave' : 'master';
         $this->assertConnectionRole($connection, $expectedRole);
     }
     return $connection;
 }
All Usage Examples Of Predis\Replication\ReplicationStrategy::isReadOperation