executeRaw() public method

It is possible to identify Redis error responses from normal responses using the second optional argument which is populated by reference.
public executeRaw ( array $arguments, boolean &$error = null ) : mixed
$arguments array Command arguments as defined by the command signature.
$error boolean Set to TRUE when Redis returned an error response.
return mixed
Example #1
0
 /**
  * @inheritdoc
  */
 public function execute(CommandInterface $command)
 {
     if (!$this->isConnected()) {
         throw new ConnectionException('No connection established');
     }
     return $this->client->executeRaw(array_merge([$command->getCommand()], $command->getArguments()));
 }
 /**
  * @inheritDoc
  */
 public function getAll() : array
 {
     if (!$this->client->exists($this->key)) {
         $models = $this->repository->getAll();
         if ($models) {
             $this->client->hmset($this->key, $this->repository->getAllIndexed());
         }
     } else {
         $models = [];
         $data = $this->client->executeRaw(['HGETALL', $this->key]);
         for ($i = 0; $i < count($data); ++$i) {
             /** @var DirectoryView $viewClass */
             $viewClass = $this->viewClass;
             $models[] = $viewClass::create($data[$i], $data[++$i]);
         }
     }
     return $models;
 }
Example #3
0
 /**
  * @group disconnected
  */
 public function testRawCommandNeverThrowsExceptions()
 {
     $message = 'ERR Mock error response';
     $response = new Response\Error($message);
     $connection = $this->getMock('Predis\\Connection\\ConnectionInterface');
     $connection->expects($this->once())->method('executeCommand')->with($this->isRedisCommand('PING'))->will($this->returnValue($response));
     $client = new Client($connection, array('exceptions' => true));
     $this->assertSame($message, $client->executeRaw(array('PING'), $error));
     $this->assertTrue($error);
 }