Predis to v2.2.2

This commit is contained in:
the-djmaze 2024-04-02 20:15:23 +02:00
parent f6b440adef
commit 84ffe1e552
259 changed files with 2407 additions and 9937 deletions

View file

@ -3,7 +3,8 @@
/*
* This file is part of the Predis package.
*
* (c) Daniele Alessandri <suppakilla@gmail.com>
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@ -14,10 +15,8 @@ namespace Predis\Protocol;
use Predis\CommunicationException;
/**
* Exception used to indentify errors encountered while parsing the Redis wire
* Exception used to identify errors encountered while parsing the Redis wire
* protocol.
*
* @author Daniele Alessandri <suppakilla@gmail.com>
*/
class ProtocolException extends CommunicationException
{

View file

@ -3,7 +3,8 @@
/*
* This file is part of the Predis package.
*
* (c) Daniele Alessandri <suppakilla@gmail.com>
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@ -17,8 +18,6 @@ use Predis\Connection\CompositeConnectionInterface;
/**
* Defines a pluggable protocol processor capable of serializing commands and
* deserializing responses into PHP objects directly from a connection.
*
* @author Daniele Alessandri <suppakilla@gmail.com>
*/
interface ProtocolProcessorInterface
{

View file

@ -3,7 +3,8 @@
/*
* This file is part of the Predis package.
*
* (c) Daniele Alessandri <suppakilla@gmail.com>
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@ -15,8 +16,6 @@ use Predis\Command\CommandInterface;
/**
* Defines a pluggable serializer for Redis commands.
*
* @author Daniele Alessandri <suppakilla@gmail.com>
*/
interface RequestSerializerInterface
{

View file

@ -3,7 +3,8 @@
/*
* This file is part of the Predis package.
*
* (c) Daniele Alessandri <suppakilla@gmail.com>
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@ -16,8 +17,6 @@ use Predis\Connection\CompositeConnectionInterface;
/**
* Defines a pluggable reader capable of parsing responses returned by Redis and
* deserializing them to PHP objects.
*
* @author Daniele Alessandri <suppakilla@gmail.com>
*/
interface ResponseReaderInterface
{

View file

@ -3,7 +3,8 @@
/*
* This file is part of the Predis package.
*
* (c) Daniele Alessandri <suppakilla@gmail.com>
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@ -21,9 +22,7 @@ use Predis\Protocol\ResponseReaderInterface;
* Composite protocol processor for the standard Redis wire protocol using
* pluggable handlers to serialize requests and deserialize responses.
*
* @link http://redis.io/topics/protocol
*
* @author Daniele Alessandri <suppakilla@gmail.com>
* @see http://redis.io/topics/protocol
*/
class CompositeProtocolProcessor implements ProtocolProcessorInterface
{

View file

@ -3,7 +3,8 @@
/*
* This file is part of the Predis package.
*
* (c) Daniele Alessandri <suppakilla@gmail.com>
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@ -19,9 +20,7 @@ use Predis\Protocol\ProtocolException;
* Handler for the bulk response type in the standard Redis wire protocol.
* It translates the payload to a string or a NULL.
*
* @link http://redis.io/topics/protocol
*
* @author Daniele Alessandri <suppakilla@gmail.com>
* @see http://redis.io/topics/protocol
*/
class BulkResponse implements ResponseHandlerInterface
{
@ -34,7 +33,7 @@ class BulkResponse implements ResponseHandlerInterface
if ("$length" !== $payload) {
CommunicationException::handle(new ProtocolException(
$connection, "Cannot parse '$payload' as a valid length for a bulk response."
$connection, "Cannot parse '$payload' as a valid length for a bulk response [{$connection->getParameters()}]"
));
}
@ -47,7 +46,7 @@ class BulkResponse implements ResponseHandlerInterface
}
CommunicationException::handle(new ProtocolException(
$connection, "Value '$payload' is not a valid length for a bulk response."
$connection, "Value '$payload' is not a valid length for a bulk response [{$connection->getParameters()}]"
));
return;

View file

@ -3,7 +3,8 @@
/*
* This file is part of the Predis package.
*
* (c) Daniele Alessandri <suppakilla@gmail.com>
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@ -18,9 +19,7 @@ use Predis\Response\Error;
* Handler for the error response type in the standard Redis wire protocol.
* It translates the payload to a complex response object for Predis.
*
* @link http://redis.io/topics/protocol
*
* @author Daniele Alessandri <suppakilla@gmail.com>
* @see http://redis.io/topics/protocol
*/
class ErrorResponse implements ResponseHandlerInterface
{

View file

@ -3,7 +3,8 @@
/*
* This file is part of the Predis package.
*
* (c) Daniele Alessandri <suppakilla@gmail.com>
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@ -19,9 +20,7 @@ use Predis\Protocol\ProtocolException;
* Handler for the integer response type in the standard Redis wire protocol.
* It translates the payload an integer or NULL.
*
* @link http://redis.io/topics/protocol
*
* @author Daniele Alessandri <suppakilla@gmail.com>
* @see http://redis.io/topics/protocol
*/
class IntegerResponse implements ResponseHandlerInterface
{
@ -31,12 +30,14 @@ class IntegerResponse implements ResponseHandlerInterface
public function handle(CompositeConnectionInterface $connection, $payload)
{
if (is_numeric($payload)) {
return (int) $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, "Cannot parse '$payload' as a valid numeric response [{$connection->getParameters()}]"
));
}

View file

@ -3,7 +3,8 @@
/*
* This file is part of the Predis package.
*
* (c) Daniele Alessandri <suppakilla@gmail.com>
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@ -19,9 +20,7 @@ use Predis\Protocol\ProtocolException;
* Handler for the multibulk response type in the standard Redis wire protocol.
* It returns multibulk responses as PHP arrays.
*
* @link http://redis.io/topics/protocol
*
* @author Daniele Alessandri <suppakilla@gmail.com>
* @see http://redis.io/topics/protocol
*/
class MultiBulkResponse implements ResponseHandlerInterface
{
@ -34,7 +33,7 @@ class MultiBulkResponse implements ResponseHandlerInterface
if ("$length" !== $payload) {
CommunicationException::handle(new ProtocolException(
$connection, "Cannot parse '$payload' as a valid length of a multi-bulk response."
$connection, "Cannot parse '$payload' as a valid length of a multi-bulk response [{$connection->getParameters()}]"
));
}
@ -42,10 +41,10 @@ class MultiBulkResponse implements ResponseHandlerInterface
return;
}
$list = array();
$list = [];
if ($length > 0) {
$handlersCache = array();
$handlersCache = [];
$reader = $connection->getProtocol()->getResponseReader();
for ($i = 0; $i < $length; ++$i) {

View file

@ -3,7 +3,8 @@
/*
* This file is part of the Predis package.
*
* (c) Daniele Alessandri <suppakilla@gmail.com>
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@ -15,8 +16,6 @@ use Predis\Connection\CompositeConnectionInterface;
/**
* Defines a pluggable handler used to parse a particular type of response.
*
* @author Daniele Alessandri <suppakilla@gmail.com>
*/
interface ResponseHandlerInterface
{

View file

@ -3,7 +3,8 @@
/*
* This file is part of the Predis package.
*
* (c) Daniele Alessandri <suppakilla@gmail.com>
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@ -19,9 +20,7 @@ use Predis\Response\Status;
* translates certain classes of status response to PHP objects or just returns
* the payload as a string.
*
* @link http://redis.io/topics/protocol
*
* @author Daniele Alessandri <suppakilla@gmail.com>
* @see http://redis.io/topics/protocol
*/
class StatusResponse implements ResponseHandlerInterface
{

View file

@ -3,7 +3,8 @@
/*
* This file is part of the Predis package.
*
* (c) Daniele Alessandri <suppakilla@gmail.com>
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@ -23,9 +24,7 @@ use Predis\Response\Iterator\MultiBulk as MultiBulkIterator;
* Streamable multibulk responses are not globally supported by the abstractions
* built-in into Predis, such as transactions or pipelines. Use them with care!
*
* @link http://redis.io/topics/protocol
*
* @author Daniele Alessandri <suppakilla@gmail.com>
* @see http://redis.io/topics/protocol
*/
class StreamableMultiBulkResponse implements ResponseHandlerInterface
{
@ -38,7 +37,7 @@ class StreamableMultiBulkResponse implements ResponseHandlerInterface
if ("$length" != $payload) {
CommunicationException::handle(new ProtocolException(
$connection, "Cannot parse '$payload' as a valid length for a multi-bulk response."
$connection, "Cannot parse '$payload' as a valid length for a multi-bulk response [{$connection->getParameters()}]"
));
}

View file

@ -3,7 +3,8 @@
/*
* This file is part of the Predis package.
*
* (c) Daniele Alessandri <suppakilla@gmail.com>
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@ -23,18 +24,13 @@ use Predis\Response\Status as StatusResponse;
/**
* Protocol processor for the standard Redis wire protocol.
*
* @link http://redis.io/topics/protocol
*
* @author Daniele Alessandri <suppakilla@gmail.com>
* @see http://redis.io/topics/protocol
*/
class ProtocolProcessor implements ProtocolProcessorInterface
{
protected $mbiterable;
protected $serializer;
/**
*
*/
public function __construct()
{
$this->mbiterable = false;
@ -81,7 +77,7 @@ class ProtocolProcessor implements ProtocolProcessorInterface
return new MultiBulkIterator($connection, $count);
}
$multibulk = array();
$multibulk = [];
for ($i = 0; $i < $count; ++$i) {
$multibulk[$i] = $this->read($connection);
@ -90,14 +86,16 @@ class ProtocolProcessor implements ProtocolProcessorInterface
return $multibulk;
case ':':
return (int) $payload;
$integer = (int) $payload;
return $integer == $payload ? $integer : $payload;
case '-':
return new ErrorResponse($payload);
default:
CommunicationException::handle(new ProtocolException(
$connection, "Unknown response prefix: '$prefix'."
$connection, "Unknown response prefix: '$prefix' [{$connection->getParameters()}]"
));
return;

View file

@ -3,7 +3,8 @@
/*
* This file is part of the Predis package.
*
* (c) Daniele Alessandri <suppakilla@gmail.com>
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@ -17,9 +18,7 @@ use Predis\Protocol\RequestSerializerInterface;
/**
* Request serializer for the standard Redis wire protocol.
*
* @link http://redis.io/topics/protocol
*
* @author Daniele Alessandri <suppakilla@gmail.com>
* @see http://redis.io/topics/protocol
*/
class RequestSerializer implements RequestSerializerInterface
{
@ -36,8 +35,7 @@ class RequestSerializer implements RequestSerializerInterface
$buffer = "*{$reqlen}\r\n\${$cmdlen}\r\n{$commandID}\r\n";
for ($i = 0, $reqlen--; $i < $reqlen; ++$i) {
$argument = $arguments[$i];
foreach ($arguments as $argument) {
$arglen = strlen($argument);
$buffer .= "\${$arglen}\r\n{$argument}\r\n";
}

View file

@ -3,7 +3,8 @@
/*
* This file is part of the Predis package.
*
* (c) Daniele Alessandri <suppakilla@gmail.com>
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@ -19,17 +20,12 @@ use Predis\Protocol\ResponseReaderInterface;
/**
* Response reader for the standard Redis wire protocol.
*
* @link http://redis.io/topics/protocol
*
* @author Daniele Alessandri <suppakilla@gmail.com>
* @see http://redis.io/topics/protocol
*/
class ResponseReader implements ResponseReaderInterface
{
protected $handlers;
/**
*
*/
public function __construct()
{
$this->handlers = $this->getDefaultHandlers();
@ -42,13 +38,13 @@ class ResponseReader implements ResponseReaderInterface
*/
protected function getDefaultHandlers()
{
return array(
return [
'+' => new Handler\StatusResponse(),
'-' => new Handler\ErrorResponse(),
':' => new Handler\IntegerResponse(),
'$' => new Handler\BulkResponse(),
'*' => new Handler\MultiBulkResponse(),
);
];
}
/**
@ -86,18 +82,16 @@ class ResponseReader implements ResponseReaderInterface
$header = $connection->readLine();
if ($header === '') {
$this->onProtocolError($connection, 'Unexpected empty reponse header.');
$this->onProtocolError($connection, 'Unexpected empty response header');
}
$prefix = $header[0];
if (!isset($this->handlers[$prefix])) {
$this->onProtocolError($connection, "Unknown response prefix: '$prefix'.");
$this->onProtocolError($connection, "Unknown response prefix: '$prefix'");
}
$payload = $this->handlers[$prefix]->handle($connection, substr($header, 1));
return $payload;
return $this->handlers[$prefix]->handle($connection, substr($header, 1));
}
/**
@ -110,7 +104,7 @@ class ResponseReader implements ResponseReaderInterface
protected function onProtocolError(CompositeConnectionInterface $connection, $message)
{
CommunicationException::handle(
new ProtocolException($connection, $message)
new ProtocolException($connection, "$message [{$connection->getParameters()}]")
);
}
}