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 |
/** * {@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; }
/** * {@inheritdoc} */ public function getConnectionByCommand(CommandInterface $command) { if (!$this->current) { if ($this->strategy->isReadOperation($command) && ($slave = $this->pickSlave())) { $this->current = $slave; } else { $this->current = $this->getMasterOrDie(); } return $this->current; } if ($this->current === ($master = $this->getMasterOrDie())) { return $master; } if (!$this->strategy->isReadOperation($command) || !$this->slaves) { $this->current = $master; } return $this->current; }
/** * @group disconnected */ public function testSetLuaScriptAsReadOperationWorksWithScriptedCommandAndCallableCheck() { $strategy = new ReplicationStrategy(); $command = $this->getMock('Predis\\Command\\ScriptedCommand', array('getScript')); $command->expects($this->any())->method('getScript')->will($this->returnValue($script = 'return true')); $command->setArguments(array('trigger', false)); $strategy->setScriptReadOnly($script, true); $this->assertTrue($strategy->isReadOperation($command)); }