mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-31 04:59:21 +03:00
Predis to v2.2.2
This commit is contained in:
parent
f6b440adef
commit
84ffe1e552
259 changed files with 2407 additions and 9937 deletions
|
|
@ -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,11 +19,10 @@ use Predis\Connection\NodeConnectionInterface;
|
|||
use Predis\Response\ErrorInterface as ErrorResponseInterface;
|
||||
use Predis\Response\ResponseInterface;
|
||||
use Predis\Response\ServerException;
|
||||
use SplQueue;
|
||||
|
||||
/**
|
||||
* Command pipeline wrapped into a MULTI / EXEC transaction.
|
||||
*
|
||||
* @author Daniele Alessandri <suppakilla@gmail.com>
|
||||
*/
|
||||
class Atomic extends Pipeline
|
||||
{
|
||||
|
|
@ -31,9 +31,9 @@ class Atomic extends Pipeline
|
|||
*/
|
||||
public function __construct(ClientInterface $client)
|
||||
{
|
||||
if (!$client->getProfile()->supportsCommands(array('multi', 'exec', 'discard'))) {
|
||||
if (!$client->getCommandFactory()->supports('multi', 'exec', 'discard')) {
|
||||
throw new ClientException(
|
||||
"The current profile does not support 'MULTI', 'EXEC' and 'DISCARD'."
|
||||
"'MULTI', 'EXEC' and 'DISCARD' are not supported by the current command factory."
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -59,10 +59,10 @@ class Atomic extends Pipeline
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function executePipeline(ConnectionInterface $connection, \SplQueue $commands)
|
||||
protected function executePipeline(ConnectionInterface $connection, SplQueue $commands)
|
||||
{
|
||||
$profile = $this->getClient()->getProfile();
|
||||
$connection->executeCommand($profile->createCommand('multi'));
|
||||
$commandFactory = $this->getClient()->getCommandFactory();
|
||||
$connection->executeCommand($commandFactory->create('multi'));
|
||||
|
||||
foreach ($commands as $command) {
|
||||
$connection->writeRequest($command);
|
||||
|
|
@ -72,15 +72,14 @@ class Atomic extends Pipeline
|
|||
$response = $connection->readResponse($command);
|
||||
|
||||
if ($response instanceof ErrorResponseInterface) {
|
||||
$connection->executeCommand($profile->createCommand('discard'));
|
||||
$connection->executeCommand($commandFactory->create('discard'));
|
||||
throw new ServerException($response->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
$executed = $connection->executeCommand($profile->createCommand('exec'));
|
||||
$executed = $connection->executeCommand($commandFactory->create('exec'));
|
||||
|
||||
if (!isset($executed)) {
|
||||
// TODO: should be throwing a more appropriate exception.
|
||||
throw new ClientException(
|
||||
'The underlying transaction has been aborted by the server.'
|
||||
);
|
||||
|
|
@ -95,7 +94,7 @@ class Atomic extends Pipeline
|
|||
);
|
||||
}
|
||||
|
||||
$responses = array();
|
||||
$responses = [];
|
||||
$sizeOfPipe = count($commands);
|
||||
$exceptions = $this->throwServerExceptions();
|
||||
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -12,18 +13,15 @@
|
|||
namespace Predis\Pipeline;
|
||||
|
||||
use Predis\CommunicationException;
|
||||
use Predis\Connection\Aggregate\ClusterInterface;
|
||||
use Predis\Connection\Cluster\ClusterInterface;
|
||||
use Predis\Connection\ConnectionInterface;
|
||||
use Predis\Connection\NodeConnectionInterface;
|
||||
use Predis\NotSupportedException;
|
||||
use SplQueue;
|
||||
|
||||
/**
|
||||
* Command pipeline that does not throw exceptions on connection errors, but
|
||||
* returns the exception instances as the rest of the response elements.
|
||||
*
|
||||
* @todo Awful naming!
|
||||
*
|
||||
* @author Daniele Alessandri <suppakilla@gmail.com>
|
||||
*/
|
||||
class ConnectionErrorProof extends Pipeline
|
||||
{
|
||||
|
|
@ -38,7 +36,7 @@ class ConnectionErrorProof extends Pipeline
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function executePipeline(ConnectionInterface $connection, \SplQueue $commands)
|
||||
protected function executePipeline(ConnectionInterface $connection, SplQueue $commands)
|
||||
{
|
||||
if ($connection instanceof NodeConnectionInterface) {
|
||||
return $this->executeSingleNode($connection, $commands);
|
||||
|
|
@ -54,9 +52,9 @@ class ConnectionErrorProof extends Pipeline
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function executeSingleNode(NodeConnectionInterface $connection, \SplQueue $commands)
|
||||
protected function executeSingleNode(NodeConnectionInterface $connection, SplQueue $commands)
|
||||
{
|
||||
$responses = array();
|
||||
$responses = [];
|
||||
$sizeOfPipe = count($commands);
|
||||
|
||||
foreach ($commands as $command) {
|
||||
|
|
@ -86,14 +84,14 @@ class ConnectionErrorProof extends Pipeline
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function executeCluster(ClusterInterface $connection, \SplQueue $commands)
|
||||
protected function executeCluster(ClusterInterface $connection, SplQueue $commands)
|
||||
{
|
||||
$responses = array();
|
||||
$responses = [];
|
||||
$sizeOfPipe = count($commands);
|
||||
$exceptions = array();
|
||||
$exceptions = [];
|
||||
|
||||
foreach ($commands as $command) {
|
||||
$cmdConnection = $connection->getConnection($command);
|
||||
$cmdConnection = $connection->getConnectionByCommand($command);
|
||||
|
||||
if (isset($exceptions[spl_object_hash($cmdConnection)])) {
|
||||
continue;
|
||||
|
|
@ -109,7 +107,7 @@ class ConnectionErrorProof extends Pipeline
|
|||
for ($i = 0; $i < $sizeOfPipe; ++$i) {
|
||||
$command = $commands->dequeue();
|
||||
|
||||
$cmdConnection = $connection->getConnection($command);
|
||||
$cmdConnection = $connection->getConnectionByCommand($command);
|
||||
$connectionHash = spl_object_hash($cmdConnection);
|
||||
|
||||
if (isset($exceptions[$connectionHash])) {
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -12,18 +13,17 @@
|
|||
namespace Predis\Pipeline;
|
||||
|
||||
use Predis\Connection\ConnectionInterface;
|
||||
use SplQueue;
|
||||
|
||||
/**
|
||||
* Command pipeline that writes commands to the servers but discards responses.
|
||||
*
|
||||
* @author Daniele Alessandri <suppakilla@gmail.com>
|
||||
*/
|
||||
class FireAndForget extends Pipeline
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function executePipeline(ConnectionInterface $connection, \SplQueue $commands)
|
||||
protected function executePipeline(ConnectionInterface $connection, SplQueue $commands)
|
||||
{
|
||||
while (!$commands->isEmpty()) {
|
||||
$connection->writeRequest($commands->dequeue());
|
||||
|
|
@ -31,6 +31,6 @@ class FireAndForget extends Pipeline
|
|||
|
||||
$connection->disconnect();
|
||||
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,30 +12,31 @@
|
|||
|
||||
namespace Predis\Pipeline;
|
||||
|
||||
use Exception;
|
||||
use InvalidArgumentException;
|
||||
use Predis\ClientContextInterface;
|
||||
use Predis\ClientException;
|
||||
use Predis\ClientInterface;
|
||||
use Predis\Command\CommandInterface;
|
||||
use Predis\Connection\Aggregate\ReplicationInterface;
|
||||
use Predis\Connection\ConnectionInterface;
|
||||
use Predis\Connection\Replication\ReplicationInterface;
|
||||
use Predis\Response\ErrorInterface as ErrorResponseInterface;
|
||||
use Predis\Response\ResponseInterface;
|
||||
use Predis\Response\ServerException;
|
||||
use SplQueue;
|
||||
|
||||
/**
|
||||
* Implementation of a command pipeline in which write and read operations of
|
||||
* Redis commands are pipelined to alleviate the effects of network round-trips.
|
||||
*
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @author Daniele Alessandri <suppakilla@gmail.com>
|
||||
*/
|
||||
class Pipeline implements ClientContextInterface
|
||||
{
|
||||
private $client;
|
||||
protected $client;
|
||||
private $pipeline;
|
||||
|
||||
private $responses = array();
|
||||
private $responses = [];
|
||||
private $running = false;
|
||||
|
||||
/**
|
||||
|
|
@ -43,7 +45,7 @@ class Pipeline implements ClientContextInterface
|
|||
public function __construct(ClientInterface $client)
|
||||
{
|
||||
$this->client = $client;
|
||||
$this->pipeline = new \SplQueue();
|
||||
$this->pipeline = new SplQueue();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -112,7 +114,7 @@ class Pipeline implements ClientContextInterface
|
|||
$connection = $this->getClient()->getConnection();
|
||||
|
||||
if ($connection instanceof ReplicationInterface) {
|
||||
$connection->switchTo('master');
|
||||
$connection->switchToMaster();
|
||||
}
|
||||
|
||||
return $connection;
|
||||
|
|
@ -123,17 +125,17 @@ class Pipeline implements ClientContextInterface
|
|||
* from the current connection.
|
||||
*
|
||||
* @param ConnectionInterface $connection Current connection instance.
|
||||
* @param \SplQueue $commands Queued commands.
|
||||
* @param SplQueue $commands Queued commands.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function executePipeline(ConnectionInterface $connection, \SplQueue $commands)
|
||||
protected function executePipeline(ConnectionInterface $connection, SplQueue $commands)
|
||||
{
|
||||
foreach ($commands as $command) {
|
||||
$connection->writeRequest($command);
|
||||
}
|
||||
|
||||
$responses = array();
|
||||
$responses = [];
|
||||
$exceptions = $this->throwServerExceptions();
|
||||
|
||||
while (!$commands->isEmpty()) {
|
||||
|
|
@ -165,7 +167,7 @@ class Pipeline implements ClientContextInterface
|
|||
$responses = $this->executePipeline($this->getConnection(), $this->pipeline);
|
||||
$this->responses = array_merge($this->responses, $responses);
|
||||
} else {
|
||||
$this->pipeline = new \SplQueue();
|
||||
$this->pipeline = new SplQueue();
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
|
@ -192,15 +194,14 @@ class Pipeline implements ClientContextInterface
|
|||
*
|
||||
* @param mixed $callable Optional callback for execution.
|
||||
*
|
||||
* @throws \Exception
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @return array
|
||||
* @throws Exception
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function execute($callable = null)
|
||||
{
|
||||
if ($callable && !is_callable($callable)) {
|
||||
throw new \InvalidArgumentException('The argument must be a callable object.');
|
||||
throw new InvalidArgumentException('The argument must be a callable object.');
|
||||
}
|
||||
|
||||
$exception = null;
|
||||
|
|
@ -212,7 +213,7 @@ class Pipeline implements ClientContextInterface
|
|||
}
|
||||
|
||||
$this->flushPipeline();
|
||||
} catch (\Exception $exception) {
|
||||
} catch (Exception $exception) {
|
||||
// NOOP
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue