示例#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;
 }
示例#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);
     }
 }
示例#3
0
文件: Pool.php 项目: 0x20h/phloppy
 /**
  * return the internal stream url.
  *
  * @return string
  */
 public function getNodeUrl()
 {
     return $this->connected->getNodeUrl();
 }
示例#4
0
 protected function tearDown()
 {
     if ($this->stream) {
         $this->stream->close();
     }
 }