/** * {@inheritdoc} */ public function getDefault(IClientOptions $options) { $profile = ServerProfile::getDefault(); if (isset($options->prefix)) { $profile->setProcessor($options->prefix); } return $profile; }
/** * @group disconnected */ public function testConstructorOpensContext() { $cmdMonitor = ServerProfile::getDefault()->createCommand('monitor'); $connection = $this->getMock('Predis\\Network\\IConnectionSingle'); $client = $this->getMock('Predis\\Client', array('createCommand', 'executeCommand'), array($connection)); $client->expects($this->once())->method('createCommand')->with('monitor', array())->will($this->returnValue($cmdMonitor)); $client->expects($this->once())->method('executeCommand')->with($cmdMonitor); $monitor = new MonitorContext($client); }
/** * @group disconnected */ public function testExecuteCommandDoesNotSendCommandsWithoutExecute() { $profile = ServerProfile::getDefault(); $executor = $this->getMock('Predis\\Pipeline\\IPipelineExecutor'); $executor->expects($this->never())->method('executor'); $pipeline = new PipelineContext(new Client(), array('executor' => $executor)); $pipeline->executeCommand($profile->createCommand('echo', array('one'))); $pipeline->executeCommand($profile->createCommand('echo', array('two'))); $pipeline->executeCommand($profile->createCommand('echo', array('three'))); }
/** * @group disconnected */ public function testExecutesCommandOnCorrectConnection() { $command = ServerProfile::getDefault()->createCommand('get', array('node01:5431')); $connection1 = $this->getMockConnection('tcp://host1:7001'); $connection1->expects($this->once())->method('executeCommand')->with($command); $connection2 = $this->getMockConnection('tcp://host1:7002'); $connection2->expects($this->never())->method('executeCommand'); $cluster = new PredisCluster(); $cluster->add($connection1); $cluster->add($connection2); $cluster->executeCommand($command); }
/** * @group disconnected */ public function testChainOfProcessors() { $processor = $this->getMock('Predis\\Commands\\Processors\\ICommandProcessor'); $processor->expects($this->exactly(2))->method('process'); $chain = new ProcessorChain(); $chain->add($processor); $chain->add($processor); $profile = ServerProfile::getDefault(); $profile->setProcessor($chain); $profile->createCommand('info'); }
/** * @group disconnected */ public function testAcceptsCallableToOverrideReadOnlyFlagForCommands() { $profile = ServerProfile::getDefault(); $cmdExistsFoo = $profile->createCommand('exists', array('foo')); $cmdExistsBar = $profile->createCommand('exists', array('bar')); $master = $this->getMockConnection('tcp://host1?alias=master'); $master->expects($this->once())->method('executeCommand')->with($cmdExistsBar); $slave1 = $this->getMockConnection('tcp://host2?alias=slave1'); $slave1->expects($this->once())->method('executeCommand')->with($cmdExistsFoo); $replication = new MasterSlaveReplication(); $replication->add($master); $replication->add($slave1); $replication->setCommandReadOnly('exists', function ($cmd) { list($arg1) = $cmd->getArguments(); return $arg1 === 'foo'; }); $replication->executeCommand($cmdExistsFoo); $replication->executeCommand($cmdExistsBar); }
/** * {@inheritdoc} */ public function create($parameters, IServerProfile $profile = null) { if (!$parameters instanceof IConnectionParameters) { $parameters = new ConnectionParameters($parameters ?: array()); } $scheme = $parameters->scheme; if (!isset($this->schemes[$scheme])) { throw new \InvalidArgumentException("Unknown connection scheme: {$scheme}"); } $initializer = $this->schemes[$scheme]; if (!is_callable($initializer)) { $connection = new $initializer($parameters); $this->prepareConnection($connection, $profile ?: ServerProfile::getDefault()); return $connection; } $connection = call_user_func($initializer, $parameters, $profile); if (!$connection instanceof IConnectionSingle) { throw new \InvalidArgumentException('Objects returned by connection initializers must implement ' . 'the Predis\\Network\\IConnectionSingle interface'); } return $connection; }
/** * @group disconnected */ public function testValidationDoesNotSetPrefixProcessorWhenValueIsProfileInstance() { $options = $this->getMock('Predis\\Options\\ClientOptions', array('__isset', '__get')); $options->expects($this->never())->method('__isset'); $options->expects($this->never())->method('__get'); $option = new ClientProfile(); $profile = $option->filter($options, ServerProfile::getDefault()); $this->assertInstanceOf('Predis\\Profiles\\IServerProfile', $profile); $this->assertNull($profile->getProcessor()); }
/** * @group disconnected */ public function testCallingRedisCommandExecutesInstanceOfCommand() { $ping = ServerProfile::getDefault()->createCommand('ping', array()); $connection = $this->getMock('Predis\\Network\\IConnection'); $connection->expects($this->once())->method('executeCommand')->with($this->isInstanceOf('Predis\\Commands\\ConnectionPing'))->will($this->returnValue(true)); $profile = $this->getMock('Predis\\Profiles\\IServerProfile'); $profile->expects($this->once())->method('createCommand')->with('ping', array())->will($this->returnValue($ping)); $client = $this->getMock('Predis\\Client', array('createCommand'), array($connection, $profile)); $this->assertTrue($client->ping()); }
/** * {@inheritdoc} */ public function getDefault() { return ServerProfile::getDefault(); }