作者:kchhainaron
项目:chantuch
/**
* 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;
}
作者:sabban
项目:studio_app
/**
* {@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;
}
作者:GeorgeBroadle
项目:caffeine-vendo
/**
* 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;
}
作者:qinzh
项目:wxmen
/**
* 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);
}
作者:sabban
项目:studio_app
/**
* {@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);
}
作者:rodrigopbe
项目:on
/**
* @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);
}
作者:flachesi
项目:predi
/**
* {@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;
}
作者:GeorgeBroadle
项目:caffeine-vendo
/**
* 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;
}
作者:nr
项目:predi
/**
* {@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;
}
作者:qinzh
项目:wxmen
/**
* 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;
}
}
作者:huyca
项目:yodeliver
/**
* {@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;
}
作者:nr
项目:predi
/**
* {@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;
}
}
作者:rodrigopbe
项目:on
/**
* {@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}'"));
}
}
作者:nr
项目:predi
/**
* 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()}]"));
}
作者:hexcode00
项目:yfcm
/**
* 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));
}
作者:rodrigopbe
项目:on
/**
* Helper method used to handle a protocol error generated while reading a
* reply from a connection to Redis.
*
* @param ComposableConnectionInterface $connection Connection to Redis that generated the error.
* @param string $message Error message.
*/
private function protocolError(ComposableConnectionInterface $connection, $message)
{
CommunicationException::handle(new ProtocolException($connection, $message));
}
作者:qinzh
项目:wxmen
/**
* Helper method to handle protocol errors.
*
* @param string $message Error message.
*/
protected function onProtocolError($message)
{
CommunicationException::handle(new ProtocolException($this, "{$message} [{$this->parameters->scheme}://{$this->getIdentifier()}]"));
}
作者:sabban
项目:studio_app
/**
* Helper method to handle protocol errors.
*
* @param string $message Error message.
*/
protected function onProtocolError($message)
{
CommunicationException::handle(new ProtocolException($this, static::createExceptionMessage($message)));
}
作者:flachesi
项目:predi
/**
* 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));
}
作者:eddy
项目:MT4-Member-Syste
/**
* Helper method to handle protocol errors.
*
* @param string $message Error message.
*/
protected function onProtocolError($message)
{
CommunicationException::handle(new ProtocolException($this, $message));
}