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.
@@ -11,15 +12,15 @@
namespace Predis\Connection;
use InvalidArgumentException;
use Predis\Command\CommandInterface;
use Predis\Command\RawCommand;
use Predis\CommunicationException;
use Predis\Protocol\ProtocolException;
/**
* Base class with the common logic used by connection classes to communicate
* with Redis.
*
* @author Daniele Alessandri <suppakilla@gmail.com>
*/
abstract class AbstractConnection implements NodeConnectionInterface
{
@@ -27,7 +28,11 @@ abstract class AbstractConnection implements NodeConnectionInterface
private $cachedId;
protected $parameters;
protected $initCommands = array();
/**
* @var RawCommand[]
*/
protected $initCommands = [];
/**
* @param ParametersInterface $parameters Initialization parameters for the connection.
@@ -51,24 +56,10 @@ abstract class AbstractConnection implements NodeConnectionInterface
*
* @param ParametersInterface $parameters Initialization parameters for the connection.
*
* @throws \InvalidArgumentException
*
* @return ParametersInterface
* @throws InvalidArgumentException
*/
protected function assertParameters(ParametersInterface $parameters)
{
switch ($parameters->scheme) {
case 'tcp':
case 'redis':
case 'unix':
break;
default:
throw new \InvalidArgumentException("Invalid scheme: '$parameters->scheme'.");
}
return $parameters;
}
abstract protected function assertParameters(ParametersInterface $parameters);
/**
* Creates the underlying resource used to communicate with Redis.
@@ -115,6 +106,14 @@ abstract class AbstractConnection implements NodeConnectionInterface
$this->initCommands[] = $command;
}
/**
* {@inheritdoc}
*/
public function getInitCommands(): array
{
return $this->initCommands;
}
/**
* {@inheritdoc}
*/
@@ -133,39 +132,16 @@ abstract class AbstractConnection implements NodeConnectionInterface
return $this->read();
}
/**
* Helper method that returns an exception message augmented with useful
* details from the connection parameters.
*
* @param string $message Error message.
*
* @return string
*/
private function createExceptionMessage($message)
{
$parameters = $this->parameters;
if ($parameters->scheme === 'unix') {
return "$message [$parameters->scheme:$parameters->path]";
}
if (filter_var($parameters->host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
return "$message [$parameters->scheme://[$parameters->host]:$parameters->port]";
}
return "$message [$parameters->scheme://$parameters->host:$parameters->port]";
}
/**
* Helper method to handle connection errors.
*
* @param string $message Error message.
* @param int $code Error code.
*/
protected function onConnectionError($message, $code = null)
protected function onConnectionError($message, $code = 0)
{
CommunicationException::handle(
new ConnectionException($this, static::createExceptionMessage($message), $code)
new ConnectionException($this, "$message [{$this->getParameters()}]", $code)
);
}
@@ -177,7 +153,7 @@ abstract class AbstractConnection implements NodeConnectionInterface
protected function onProtocolError($message)
{
CommunicationException::handle(
new ProtocolException($this, static::createExceptionMessage($message))
new ProtocolException($this, "$message [{$this->getParameters()}]")
);
}
@@ -234,6 +210,6 @@ abstract class AbstractConnection implements NodeConnectionInterface
*/
public function __sleep()
{
return array('parameters', 'initCommands');
return ['parameters', 'initCommands'];
}
}