Exemplo n.º 1
0
 /**
  * Send request and retrieve response to the connected disque node.
  *
  * @param array $args
  * @return array|int|null|string
  *
  * @throws CommandException
  * @throws StreamException
  */
 protected function send(array $args = [])
 {
     $this->log->debug('send()ing command', $args);
     $response = RespUtils::deserialize($this->stream->write(RespUtils::serialize($args)));
     $this->log->debug('response', [$response]);
     return $response;
 }
Exemplo n.º 2
0
 /**
  * @param StreamInterface $stream
  *
  * @return array|int|null|string
  *
  * @throws CommandException
  * @throws \RuntimeException
  */
 public static function deserialize(StreamInterface $stream)
 {
     $rsp = $stream->readLine();
     list($type, $result) = [$rsp[0], trim(substr($rsp, 1, strlen($rsp)))];
     switch ($type) {
         case '-':
             // ERRORS
             throw new CommandException($result);
         case '+':
             // SIMPLE STRINGS
             return $result;
         case ':':
             // INTEGERS
             return (int) $result;
         case '$':
             // BULK STRINGS
             $result = (int) $result;
             if ($result == -1) {
                 return null;
             }
             return trim($stream->readBytes($result + 2));
         case '*':
             // ARRAYS
             $cnt = (int) $result;
             $out = [];
             for ($i = 0; $i < $cnt; $i++) {
                 $out[] = static::deserialize($stream);
             }
             return $out;
         default:
             throw new \RuntimeException('unhandled protocol response: ' . $rsp);
     }
 }
Exemplo n.º 3
0
 /**
  * return the internal stream url.
  *
  * @return string
  */
 public function getNodeUrl()
 {
     return $this->connected->getNodeUrl();
 }
Exemplo n.º 4
0
 protected function tearDown()
 {
     if ($this->stream) {
         $this->stream->close();
     }
 }