当前位置: 首页>>代码示例>>PHP>>正文


PHP Predis\CommunicationException类代码示例

本文整理汇总了PHP中Predis\CommunicationException的典型用法代码示例。如果您正苦于以下问题:PHP CommunicationException类的具体用法?PHP CommunicationException怎么用?PHP CommunicationException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了CommunicationException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: handle

 /**
  * Offers a generic and reusable method to handle exceptions generated by
  * a connection object.
  *
  * @param CommunicationException $exception Exception.
  */
 public static function handle(CommunicationException $exception)
 {
     if ($exception->shouldResetConnection()) {
         $connection = $exception->getConnection();
         if ($connection->isConnected()) {
             $connection->disconnect();
         }
     }
     throw $exception;
 }
开发者ID:kchhainarong,项目名称:chantuchP,代码行数:16,代码来源:CommunicationException.php

示例2: handle

 /**
  * {@inheritdoc}
  */
 public function handle(CompositeConnectionInterface $connection, $payload)
 {
     $length = (int) $payload;
     if ("{$length}" !== $payload) {
         CommunicationException::handle(new ProtocolException($connection, "Cannot parse '{$payload}' as a valid length of a multi-bulk response."));
     }
     if ($length === -1) {
         return;
     }
     $list = array();
     if ($length > 0) {
         $handlersCache = array();
         $reader = $connection->getProtocol()->getResponseReader();
         for ($i = 0; $i < $length; ++$i) {
             $header = $connection->readLine();
             $prefix = $header[0];
             if (isset($handlersCache[$prefix])) {
                 $handler = $handlersCache[$prefix];
             } else {
                 $handler = $reader->getHandler($prefix);
                 $handlersCache[$prefix] = $handler;
             }
             $list[$i] = $handler->handle($connection, substr($header, 1));
         }
     }
     return $list;
 }
开发者ID:sabbana,项目名称:studio_apps,代码行数:30,代码来源:MultiBulkResponse.php

示例3: handle

 /**
  * Handles a multi-bulk reply returned by Redis.
  *
  * @param  ComposableConnectionInterface $connection   Connection to Redis.
  * @param  string                        $lengthString Number of items in the multi-bulk reply.
  * @return array
  */
 public function handle(ComposableConnectionInterface $connection, $lengthString)
 {
     $length = (int) $lengthString;
     if ("{$length}" !== $lengthString) {
         CommunicationException::handle(new ProtocolException($connection, "Cannot parse '{$lengthString}' as multi-bulk length"));
     }
     if ($length === -1) {
         return null;
     }
     $list = array();
     if ($length > 0) {
         $handlersCache = array();
         $reader = $connection->getProtocol()->getReader();
         for ($i = 0; $i < $length; $i++) {
             $header = $connection->readLine();
             $prefix = $header[0];
             if (isset($handlersCache[$prefix])) {
                 $handler = $handlersCache[$prefix];
             } else {
                 $handler = $reader->getHandler($prefix);
                 $handlersCache[$prefix] = $handler;
             }
             $list[$i] = $handler->handle($connection, substr($header, 1));
         }
     }
     return $list;
 }
开发者ID:GeorgeBroadley,项目名称:caffeine-vendor,代码行数:34,代码来源:ResponseMultiBulkHandler.php

示例4: handle

 /**
  * Handles a multi-bulk reply returned by Redis in a streamable fashion.
  *
  * @param ComposableConnectionInterface $connection Connection to Redis.
  * @param string $lengthString Number of items in the multi-bulk reply.
  * @return MultiBulkResponseSimple
  */
 public function handle(ComposableConnectionInterface $connection, $lengthString)
 {
     $length = (int) $lengthString;
     if ("{$length}" != $lengthString) {
         CommunicationException::handle(new ProtocolException($connection, "Cannot parse '{$lengthString}' as multi-bulk length"));
     }
     return new MultiBulkResponseSimple($connection, $length);
 }
开发者ID:qinzhe,项目名称:wxmenu,代码行数:15,代码来源:ResponseMultiBulkStreamHandler.php

示例5: handle

 /**
  * {@inheritdoc}
  */
 public function handle(CompositeConnectionInterface $connection, $payload)
 {
     $length = (int) $payload;
     if ("{$length}" != $payload) {
         CommunicationException::handle(new ProtocolException($connection, "Cannot parse '{$payload}' as a valid length for a multi-bulk response."));
     }
     return new MultiBulkIterator($connection, $length);
 }
开发者ID:sabbana,项目名称:studio_apps,代码行数:11,代码来源:StreamableMultiBulkResponse.php

示例6: testCommunicationExceptionHandling

 /**
  * @group disconnected
  * @expectedException Predis\CommunicationException
  * @expectedExceptionMessage Communication error
  */
 public function testCommunicationExceptionHandling()
 {
     $connection = $this->getMock('Predis\\Connection\\SingleConnectionInterface');
     $connection->expects($this->once())->method('isConnected')->will($this->returnValue(true));
     $connection->expects($this->once())->method('disconnect');
     $exception = $this->getException($connection, 'Communication error');
     CommunicationException::handle($exception);
 }
开发者ID:rodrigopbel,项目名称:ong,代码行数:13,代码来源:CommunicationExceptionTest.php

示例7: handle

 /**
  * {@inheritdoc}
  */
 public function handle(CompositeConnectionInterface $connection, $payload)
 {
     if (is_numeric($payload)) {
         return (int) $payload;
     }
     if ($payload !== 'nil') {
         CommunicationException::handle(new ProtocolException($connection, "Cannot parse '{$payload}' as a valid numeric response."));
     }
     return;
 }
开发者ID:flachesis,项目名称:predis,代码行数:13,代码来源:IntegerResponse.php

示例8: handle

 /**
  * Handles an integer reply returned by Redis.
  *
  * @param  ComposableConnectionInterface $connection Connection to Redis.
  * @param  string                        $number     String representation of an integer.
  * @return int
  */
 public function handle(ComposableConnectionInterface $connection, $number)
 {
     if (is_numeric($number)) {
         return (int) $number;
     }
     if ($number !== 'nil') {
         CommunicationException::handle(new ProtocolException($connection, "Cannot parse '{$number}' as numeric response"));
     }
     return null;
 }
开发者ID:GeorgeBroadley,项目名称:caffeine-vendor,代码行数:17,代码来源:ResponseIntegerHandler.php

示例9: handle

 /**
  * {@inheritdoc}
  */
 public function handle(CompositeConnectionInterface $connection, $payload)
 {
     if (is_numeric($payload)) {
         $integer = (int) $payload;
         return $integer == $payload ? $integer : $payload;
     }
     if ($payload !== 'nil') {
         CommunicationException::handle(new ProtocolException($connection, "Cannot parse '{$payload}' as a valid numeric response [{$connection->getParameters()}]"));
     }
     return;
 }
开发者ID:nrk,项目名称:predis,代码行数:14,代码来源:IntegerResponse.php

示例10: handle

 /**
  * Handles a bulk reply returned by Redis.
  *
  * @param ComposableConnectionInterface $connection Connection to Redis.
  * @param string $lengthString Bytes size of the bulk reply.
  * @return string
  */
 public function handle(ComposableConnectionInterface $connection, $lengthString)
 {
     $length = (int) $lengthString;
     if ("{$length}" !== $lengthString) {
         CommunicationException::handle(new ProtocolException($connection, "Cannot parse '{$lengthString}' as bulk length"));
     }
     if ($length >= 0) {
         return substr($connection->readBytes($length + 2), 0, -2);
     }
     if ($length == -1) {
         return null;
     }
 }
开发者ID:qinzhe,项目名称:wxmenu,代码行数:20,代码来源:ResponseBulkHandler.php

示例11: handle

 /**
  * {@inheritdoc}
  */
 public function handle(CompositeConnectionInterface $connection, $payload)
 {
     $length = (int) $payload;
     if ("{$length}" !== $payload) {
         CommunicationException::handle(new ProtocolException($connection, "Cannot parse '{$payload}' as a valid length for a bulk response."));
     }
     if ($length >= 0) {
         return substr($connection->readBuffer($length + 2), 0, -2);
     }
     if ($length == -1) {
         return null;
     }
     CommunicationException::handle(new ProtocolException($connection, "Value '{$payload}' is not a valid length for a bulk response."));
     return;
 }
开发者ID:huycao,项目名称:yodelivery,代码行数:18,代码来源:BulkResponse.php

示例12: read

 /**
  * {@inheritdoc}
  */
 public function read(CompositeConnectionInterface $connection)
 {
     $chunk = $connection->readLine();
     $prefix = $chunk[0];
     $payload = substr($chunk, 1);
     switch ($prefix) {
         case '+':
             return new StatusResponse($payload);
         case '$':
             $size = (int) $payload;
             if ($size === -1) {
                 return;
             }
             return substr($connection->readBuffer($size + 2), 0, -2);
         case '*':
             $count = (int) $payload;
             if ($count === -1) {
                 return;
             }
             if ($this->mbiterable) {
                 return new MultiBulkIterator($connection, $count);
             }
             $multibulk = array();
             for ($i = 0; $i < $count; ++$i) {
                 $multibulk[$i] = $this->read($connection);
             }
             return $multibulk;
         case ':':
             $integer = (int) $payload;
             return $integer == $payload ? $integer : $payload;
         case '-':
             return new ErrorResponse($payload);
         default:
             CommunicationException::handle(new ProtocolException($connection, "Unknown response prefix: '{$prefix}' [{$connection->getParameters()}]"));
             return;
     }
 }
开发者ID:nrk,项目名称:predis,代码行数:40,代码来源:ProtocolProcessor.php

示例13: read

 /**
  * {@inheritdoc}
  */
 public function read(ComposableConnectionInterface $connection)
 {
     $chunk = $connection->readLine();
     $prefix = $chunk[0];
     $payload = substr($chunk, 1);
     switch ($prefix) {
         case '+':
             switch ($payload) {
                 case 'OK':
                     return true;
                 case 'QUEUED':
                     return new ResponseQueued();
                 default:
                     return $payload;
             }
         case '$':
             $size = (int) $payload;
             if ($size === -1) {
                 return null;
             }
             return substr($connection->readBytes($size + 2), 0, -2);
         case '*':
             $count = (int) $payload;
             if ($count === -1) {
                 return null;
             }
             if ($this->mbiterable) {
                 return new MultiBulkResponseSimple($connection, $count);
             }
             $multibulk = array();
             for ($i = 0; $i < $count; $i++) {
                 $multibulk[$i] = $this->read($connection);
             }
             return $multibulk;
         case ':':
             return (int) $payload;
         case '-':
             return new ResponseError($payload);
         default:
             CommunicationException::handle(new ProtocolException($connection, "Unknown prefix: '{$prefix}'"));
     }
 }
开发者ID:rodrigopbel,项目名称:ong,代码行数:45,代码来源:TextProtocol.php

示例14: onProtocolError

 /**
  * Handles protocol errors generated while reading responses from a
  * connection.
  *
  * @param CompositeConnectionInterface $connection Redis connection that generated the error.
  * @param string                       $message    Error message.
  */
 protected function onProtocolError(CompositeConnectionInterface $connection, $message)
 {
     CommunicationException::handle(new ProtocolException($connection, "{$message} [{$connection->getParameters()}]"));
 }
开发者ID:nrk,项目名称:predis,代码行数:11,代码来源:ResponseReader.php

示例15: onProtocolError

 /**
  * Helper method for protocol errors encountered inside the transaction.
  *
  * @param string $message Error message.
  */
 private function onProtocolError($message)
 {
     // Since a MULTI/EXEC block cannot be initialized when using aggregate
     // connections we can safely assume that Predis\Client::getConnection()
     // will return a Predis\Connection\NodeConnectionInterface instance.
     CommunicationException::handle(new ProtocolException($this->client->getConnection(), $message));
 }
开发者ID:hexcode007,项目名称:yfcms,代码行数:12,代码来源:MultiExec.php


注:本文中的Predis\CommunicationException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。