當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。