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,8 +12,10 @@
namespace Predis\Collection\Iterator;
use Iterator;
use Predis\ClientInterface;
use Predis\NotSupportedException;
use ReturnTypeWillChange;
/**
* Provides the base implementation for a fully-rewindable PHP iterator that can
@ -24,10 +27,8 @@ use Predis\NotSupportedException;
* can change several times during the iteration process.
*
* @see http://redis.io/commands/scan
*
* @author Daniele Alessandri <suppakilla@gmail.com>
*/
abstract class CursorBasedIterator implements \Iterator
abstract class CursorBasedIterator implements Iterator
{
protected $client;
protected $match;
@ -65,8 +66,8 @@ abstract class CursorBasedIterator implements \Iterator
*/
protected function requiredCommand(ClientInterface $client, $commandID)
{
if (!$client->getProfile()->supportsCommand($commandID)) {
throw new NotSupportedException("The current profile does not support '$commandID'.");
if (!$client->getCommandFactory()->supports($commandID)) {
throw new NotSupportedException("'$commandID' is not supported by the current command factory.");
}
}
@ -77,7 +78,7 @@ abstract class CursorBasedIterator implements \Iterator
{
$this->valid = true;
$this->fetchmore = true;
$this->elements = array();
$this->elements = [];
$this->cursor = 0;
$this->position = -1;
$this->current = null;
@ -90,9 +91,9 @@ abstract class CursorBasedIterator implements \Iterator
*/
protected function getScanOptions()
{
$options = array();
$options = [];
if (strlen($this->match) > 0) {
if (strlen(strval($this->match)) > 0) {
$options['MATCH'] = $this->match;
}
@ -117,7 +118,7 @@ abstract class CursorBasedIterator implements \Iterator
*/
protected function fetch()
{
list($cursor, $elements) = $this->executeCommand();
[$cursor, $elements] = $this->executeCommand();
if (!$cursor) {
$this->fetchmore = false;
@ -137,8 +138,9 @@ abstract class CursorBasedIterator implements \Iterator
}
/**
* {@inheritdoc}
* @return void
*/
#[ReturnTypeWillChange]
public function rewind()
{
$this->reset();
@ -146,27 +148,30 @@ abstract class CursorBasedIterator implements \Iterator
}
/**
* {@inheritdoc}
* @return mixed
*/
#[ReturnTypeWillChange]
public function current()
{
return $this->current;
}
/**
* {@inheritdoc}
* @return int|null
*/
#[ReturnTypeWillChange]
public function key()
{
return $this->position;
}
/**
* {@inheritdoc}
* @return void
*/
#[ReturnTypeWillChange]
public function next()
{
tryFetch: {
tryFetch:
if (!$this->elements && $this->fetchmore) {
$this->fetch();
}
@ -178,12 +183,12 @@ abstract class CursorBasedIterator implements \Iterator
} else {
$this->valid = false;
}
}
}
/**
* {@inheritdoc}
* @return bool
*/
#[ReturnTypeWillChange]
public function valid()
{
return $this->valid;

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\ClientInterface;
* Abstracts the iteration of fields and values of an hash by leveraging the
* HSCAN command (Redis >= 2.8) wrapped in a fully-rewindable PHP iterator.
*
* @author Daniele Alessandri <suppakilla@gmail.com>
*
* @link http://redis.io/commands/scan
* @see http://redis.io/commands/scan
*/
class HashKey extends CursorBasedIterator
{
@ -51,6 +50,8 @@ class HashKey extends CursorBasedIterator
protected function extractNext()
{
$this->position = key($this->elements);
$this->current = array_shift($this->elements);
$this->current = current($this->elements);
unset($this->elements[$this->position]);
}
}

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\ClientInterface;
* Abstracts the iteration of the keyspace on a Redis instance by leveraging the
* SCAN command (Redis >= 2.8) wrapped in a fully-rewindable PHP iterator.
*
* @author Daniele Alessandri <suppakilla@gmail.com>
*
* @link http://redis.io/commands/scan
* @see http://redis.io/commands/scan
*/
class Keyspace extends CursorBasedIterator
{

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,8 +12,11 @@
namespace Predis\Collection\Iterator;
use InvalidArgumentException;
use Iterator;
use Predis\ClientInterface;
use Predis\NotSupportedException;
use ReturnTypeWillChange;
/**
* Abstracts the iteration of items stored in a list by leveraging the LRANGE
@ -24,11 +28,9 @@ use Predis\NotSupportedException;
* guarantees on the returned elements because the collection can change several
* times (trimmed, deleted, overwritten) during the iteration process.
*
* @author Daniele Alessandri <suppakilla@gmail.com>
*
* @link http://redis.io/commands/lrange
* @see http://redis.io/commands/lrange
*/
class ListKey implements \Iterator
class ListKey implements Iterator
{
protected $client;
protected $count;
@ -45,14 +47,14 @@ class ListKey implements \Iterator
* @param string $key Redis list key.
* @param int $count Number of items retrieved on each fetch operation.
*
* @throws \InvalidArgumentException
* @throws InvalidArgumentException
*/
public function __construct(ClientInterface $client, $key, $count = 10)
{
$this->requiredCommand($client, 'LRANGE');
if ((false === $count = filter_var($count, FILTER_VALIDATE_INT)) || $count < 0) {
throw new \InvalidArgumentException('The $count argument must be a positive integer.');
throw new InvalidArgumentException('The $count argument must be a positive integer.');
}
$this->client = $client;
@ -73,8 +75,8 @@ class ListKey implements \Iterator
*/
protected function requiredCommand(ClientInterface $client, $commandID)
{
if (!$client->getProfile()->supportsCommand($commandID)) {
throw new NotSupportedException("The current profile does not support '$commandID'.");
if (!$client->getCommandFactory()->supports($commandID)) {
throw new NotSupportedException("'$commandID' is not supported by the current command factory.");
}
}
@ -85,7 +87,7 @@ class ListKey implements \Iterator
{
$this->valid = true;
$this->fetchmore = true;
$this->elements = array();
$this->elements = [];
$this->position = -1;
$this->current = null;
}
@ -126,8 +128,9 @@ class ListKey implements \Iterator
}
/**
* {@inheritdoc}
* @return void
*/
#[ReturnTypeWillChange]
public function rewind()
{
$this->reset();
@ -135,24 +138,27 @@ class ListKey implements \Iterator
}
/**
* {@inheritdoc}
* @return mixed
*/
#[ReturnTypeWillChange]
public function current()
{
return $this->current;
}
/**
* {@inheritdoc}
* @return int|null
*/
#[ReturnTypeWillChange]
public function key()
{
return $this->position;
}
/**
* {@inheritdoc}
* @return void
*/
#[ReturnTypeWillChange]
public function next()
{
if (!$this->elements && $this->fetchmore) {
@ -167,8 +173,9 @@ class ListKey implements \Iterator
}
/**
* {@inheritdoc}
* @return bool
*/
#[ReturnTypeWillChange]
public function valid()
{
return $this->valid;

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\ClientInterface;
* Abstracts the iteration of members stored in a set by leveraging the SSCAN
* command (Redis >= 2.8) wrapped in a fully-rewindable PHP iterator.
*
* @author Daniele Alessandri <suppakilla@gmail.com>
*
* @link http://redis.io/commands/scan
* @see http://redis.io/commands/scan
*/
class SetKey extends CursorBasedIterator
{

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\ClientInterface;
* Abstracts the iteration of members stored in a sorted set by leveraging the
* ZSCAN command (Redis >= 2.8) wrapped in a fully-rewindable PHP iterator.
*
* @author Daniele Alessandri <suppakilla@gmail.com>
*
* @link http://redis.io/commands/scan
* @see http://redis.io/commands/scan
*/
class SortedSetKey extends CursorBasedIterator
{
@ -50,11 +49,9 @@ class SortedSetKey extends CursorBasedIterator
*/
protected function extractNext()
{
if ($kv = each($this->elements)) {
$this->position = $kv[0];
$this->current = $kv[1];
$this->position = key($this->elements);
$this->current = current($this->elements);
unset($this->elements[$this->position]);
}
unset($this->elements[$this->position]);
}
}