本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}
示例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;
}
}
示例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}'"));
}
}
示例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()}]"));
}
示例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));
}