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,16 +12,16 @@
namespace Predis\Monitor;
use Iterator;
use Predis\ClientInterface;
use Predis\Connection\AggregateConnectionInterface;
use Predis\Connection\Cluster\ClusterInterface;
use Predis\NotSupportedException;
use ReturnTypeWillChange;
/**
* Redis MONITOR consumer.
*
* @author Daniele Alessandri <suppakilla@gmail.com>
*/
class Consumer implements \Iterator
class Consumer implements Iterator
{
private $client;
private $valid;
@ -56,14 +57,14 @@ class Consumer implements \Iterator
*/
private function assertClient(ClientInterface $client)
{
if ($client->getConnection() instanceof AggregateConnectionInterface) {
if ($client->getConnection() instanceof ClusterInterface) {
throw new NotSupportedException(
'Cannot initialize a monitor consumer over aggregate connections.'
'Cannot initialize a monitor consumer over cluster connections.'
);
}
if ($client->getProfile()->supportsCommand('MONITOR') === false) {
throw new NotSupportedException("The current profile does not support 'MONITOR'.");
if (!$client->getCommandFactory()->supports('MONITOR')) {
throw new NotSupportedException("'MONITOR' is not supported by the current command factory.");
}
}
@ -89,8 +90,9 @@ class Consumer implements \Iterator
}
/**
* {@inheritdoc}
* @return void
*/
#[ReturnTypeWillChange]
public function rewind()
{
// NOOP
@ -99,24 +101,27 @@ class Consumer implements \Iterator
/**
* Returns the last message payload retrieved from the server.
*
* @return Object
* @return object
*/
#[ReturnTypeWillChange]
public function current()
{
return $this->getValue();
}
/**
* {@inheritdoc}
* @return int|null
*/
#[ReturnTypeWillChange]
public function key()
{
return $this->position;
}
/**
* {@inheritdoc}
* @return void
*/
#[ReturnTypeWillChange]
public function next()
{
++$this->position;
@ -127,6 +132,7 @@ class Consumer implements \Iterator
*
* @return bool
*/
#[ReturnTypeWillChange]
public function valid()
{
return $this->valid;
@ -136,7 +142,7 @@ class Consumer implements \Iterator
* Waits for a new message from the server generated by MONITOR and returns
* it when available.
*
* @return Object
* @return object
*/
private function getValue()
{
@ -160,14 +166,14 @@ class Consumer implements \Iterator
};
$event = preg_replace_callback('/ \(db (\d+)\) | \[(\d+) (.*?)\] /', $callback, $event, 1);
@list($timestamp, $command, $arguments) = explode(' ', $event, 3);
@[$timestamp, $command, $arguments] = explode(' ', $event, 3);
return (object) array(
return (object) [
'timestamp' => (float) $timestamp,
'database' => $database,
'client' => $client,
'command' => substr($command, 1, -1),
'arguments' => $arguments,
);
];
}
}