Автор: Daniele Alessandri (suppakilla@gmail.com)
Наследование: implements ResponseInterface
Пример #1
0
 /**
  * @group disconnected
  */
 public function testStaticGetMethodCachesOnlyCommonStatuses()
 {
     $response = Status::get('OK');
     $this->assertSame($response, Status::get('OK'));
     $response = Status::get('QUEUED');
     $this->assertSame($response, Status::get('QUEUED'));
     $response = Status::get('PONG');
     $this->assertNotSame($response, Status::get('PONG'));
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function parseResponseBuffer($buffer)
 {
     foreach ($this->parser->pushIncoming($buffer) as $response) {
         $value = $response->getValueNative();
         if ($response instanceof StatusReply) {
             $response = StatusResponse::get($value);
         } elseif ($response instanceof ErrorReply) {
             $response = new ErrorResponse($value);
         } else {
             $response = $value;
         }
         $this->state->process($response);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function read()
 {
     $socket = $this->getResource();
     $chunk = fgets($socket);
     if ($chunk === false || $chunk === '') {
         $this->onConnectionError('Error while reading line from the server.');
     }
     $prefix = $chunk[0];
     $payload = substr($chunk, 1, -2);
     switch ($prefix) {
         case '+':
             return StatusResponse::get($payload);
         case '$':
             $size = (int) $payload;
             if ($size === -1) {
                 return;
             }
             $bulkData = '';
             $bytesLeft = $size += 2;
             do {
                 $chunk = fread($socket, min($bytesLeft, 4096));
                 if ($chunk === false || $chunk === '') {
                     $this->onConnectionError('Error while reading bytes from the server.');
                 }
                 $bulkData .= $chunk;
                 $bytesLeft = $size - strlen($bulkData);
             } while ($bytesLeft > 0);
             return substr($bulkData, 0, -2);
         case '*':
             $count = (int) $payload;
             if ($count === -1) {
                 return;
             }
             $multibulk = array();
             for ($i = 0; $i < $count; ++$i) {
                 $multibulk[$i] = $this->read();
             }
             return $multibulk;
         case ':':
             return (int) $payload;
         case '-':
             return new ErrorResponse($payload);
         default:
             $this->onProtocolError("Unknown response prefix: '{$prefix}'.");
             return;
     }
 }
Пример #4
0
 /**
  * {@inheritdoc}
  */
 public function handle(CompositeConnectionInterface $connection, $payload)
 {
     return Status::get($payload);
 }
 /**
  * Returns the handler used by the protocol reader for inline responses.
  *
  * @return \Closure
  */
 protected function getStatusHandler()
 {
     return function ($payload) {
         return StatusResponse::get($payload);
     };
 }
Пример #6
0
 /**
  * Returns the handler used by the protocol reader for inline responses.
  *
  * @return \Closure
  */
 protected function getStatusHandler()
 {
     static $statusHandler;
     if (!$statusHandler) {
         $statusHandler = function ($payload) {
             return StatusResponse::get($payload);
         };
     }
     return $statusHandler;
 }
Пример #7
0
 /**
  * Checks that response status is «OK».
  *
  * @param  \Predis\Response\Status $status
  * @return boolean
  */
 private function isStatusOk(Status $status)
 {
     return 0 === strcasecmp($status->getPayload(), 'ok');
 }