mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-08 22:18:28 +03:00
Predis to v2.2.2
This commit is contained in:
parent
9510347d3a
commit
969dca5f7e
449 changed files with 22013 additions and 2 deletions
22
plugins/cache-redis/LICENSE
Normal file
22
plugins/cache-redis/LICENSE
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2009-2020 Daniele Alessandri (original work)
|
||||
Copyright (c) 2021-2023 Till Krüss (modified work)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
64
plugins/cache-redis/Predis/Autoloader.php
Normal file
64
plugins/cache-redis/Predis/Autoloader.php
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis;
|
||||
|
||||
/**
|
||||
* Implements a lightweight PSR-0 compliant autoloader for Predis.
|
||||
*
|
||||
* @author Eric Naeseth <eric@thumbtack.com>
|
||||
* @author Daniele Alessandri <suppakilla@gmail.com>
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class Autoloader
|
||||
{
|
||||
private $directory;
|
||||
private $prefix;
|
||||
private $prefixLength;
|
||||
|
||||
/**
|
||||
* @param string $baseDirectory Base directory where the source files are located.
|
||||
*/
|
||||
public function __construct($baseDirectory = __DIR__)
|
||||
{
|
||||
$this->directory = $baseDirectory;
|
||||
$this->prefix = __NAMESPACE__ . '\\';
|
||||
$this->prefixLength = strlen($this->prefix);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the autoloader class with the PHP SPL autoloader.
|
||||
*
|
||||
* @param bool $prepend Prepend the autoloader on the stack instead of appending it.
|
||||
*/
|
||||
public static function register($prepend = false)
|
||||
{
|
||||
spl_autoload_register([new self(), 'autoload'], true, $prepend);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a class from a file using its fully qualified name.
|
||||
*
|
||||
* @param string $className Fully qualified name of a class.
|
||||
*/
|
||||
public function autoload($className)
|
||||
{
|
||||
if (0 === strpos($className, $this->prefix)) {
|
||||
$parts = explode('\\', substr($className, $this->prefixLength));
|
||||
$filepath = $this->directory . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $parts) . '.php';
|
||||
|
||||
if (is_file($filepath)) {
|
||||
require $filepath;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
42
plugins/cache-redis/Predis/ClientConfiguration.php
Normal file
42
plugins/cache-redis/Predis/ClientConfiguration.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis;
|
||||
|
||||
class ClientConfiguration
|
||||
{
|
||||
/**
|
||||
* @var array{modules: array}|string[][]
|
||||
*/
|
||||
private static $config = [
|
||||
'modules' => [
|
||||
['name' => 'Json', 'commandPrefix' => 'JSON'],
|
||||
['name' => 'BloomFilter', 'commandPrefix' => 'BF'],
|
||||
['name' => 'CuckooFilter', 'commandPrefix' => 'CF'],
|
||||
['name' => 'CountMinSketch', 'commandPrefix' => 'CMS'],
|
||||
['name' => 'TDigest', 'commandPrefix' => 'TDIGEST'],
|
||||
['name' => 'TopK', 'commandPrefix' => 'TOPK'],
|
||||
['name' => 'Search', 'commandPrefix' => 'FT'],
|
||||
['name' => 'TimeSeries', 'commandPrefix' => 'TS'],
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Returns available modules with configuration.
|
||||
*
|
||||
* @return array|string[][]
|
||||
*/
|
||||
public static function getModules(): array
|
||||
{
|
||||
return self::$config['modules'];
|
||||
}
|
||||
}
|
||||
42
plugins/cache-redis/Predis/Cluster/Hash/PhpiredisCRC16.php
Normal file
42
plugins/cache-redis/Predis/Cluster/Hash/PhpiredisCRC16.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Cluster\Hash;
|
||||
|
||||
use Predis\NotSupportedException;
|
||||
|
||||
/**
|
||||
* Hash generator implementing the CRC-CCITT-16 algorithm used by redis-cluster.
|
||||
*
|
||||
* @deprecated 2.1.2
|
||||
*/
|
||||
class PhpiredisCRC16 implements HashGeneratorInterface
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
if (!function_exists('phpiredis_utils_crc16')) {
|
||||
// @codeCoverageIgnoreStart
|
||||
throw new NotSupportedException(
|
||||
'This hash generator requires a compatible version of ext-phpiredis'
|
||||
);
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hash($value)
|
||||
{
|
||||
return phpiredis_utils_crc16($value);
|
||||
}
|
||||
}
|
||||
209
plugins/cache-redis/Predis/Cluster/SlotMap.php
Normal file
209
plugins/cache-redis/Predis/Cluster/SlotMap.php
Normal file
|
|
@ -0,0 +1,209 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Cluster;
|
||||
|
||||
use ArrayAccess;
|
||||
use ArrayIterator;
|
||||
use Countable;
|
||||
use IteratorAggregate;
|
||||
use OutOfBoundsException;
|
||||
use Predis\Connection\NodeConnectionInterface;
|
||||
use ReturnTypeWillChange;
|
||||
use Traversable;
|
||||
|
||||
/**
|
||||
* Slot map for redis-cluster.
|
||||
*/
|
||||
class SlotMap implements ArrayAccess, IteratorAggregate, Countable
|
||||
{
|
||||
private $slots = [];
|
||||
|
||||
/**
|
||||
* Checks if the given slot is valid.
|
||||
*
|
||||
* @param int $slot Slot index.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isValid($slot)
|
||||
{
|
||||
return $slot >= 0x0000 && $slot <= 0x3FFF;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given slot range is valid.
|
||||
*
|
||||
* @param int $first Initial slot of the range.
|
||||
* @param int $last Last slot of the range.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isValidRange($first, $last)
|
||||
{
|
||||
return $first >= 0x0000 && $first <= 0x3FFF && $last >= 0x0000 && $last <= 0x3FFF && $first <= $last;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the slot map.
|
||||
*/
|
||||
public function reset()
|
||||
{
|
||||
$this->slots = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the slot map is empty.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isEmpty()
|
||||
{
|
||||
return empty($this->slots);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current slot map as a dictionary of $slot => $node.
|
||||
*
|
||||
* The order of the slots in the dictionary is not guaranteed.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray()
|
||||
{
|
||||
return $this->slots;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of unique nodes in the slot map.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getNodes()
|
||||
{
|
||||
return array_keys(array_flip($this->slots));
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns the specified slot range to a node.
|
||||
*
|
||||
* @param int $first Initial slot of the range.
|
||||
* @param int $last Last slot of the range.
|
||||
* @param NodeConnectionInterface|string $connection ID or connection instance.
|
||||
*
|
||||
* @throws OutOfBoundsException
|
||||
*/
|
||||
public function setSlots($first, $last, $connection)
|
||||
{
|
||||
if (!static::isValidRange($first, $last)) {
|
||||
throw new OutOfBoundsException("Invalid slot range $first-$last for `$connection`");
|
||||
}
|
||||
|
||||
$this->slots += array_fill($first, $last - $first + 1, (string) $connection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the specified slot range.
|
||||
*
|
||||
* @param int $first Initial slot of the range.
|
||||
* @param int $last Last slot of the range.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSlots($first, $last)
|
||||
{
|
||||
if (!static::isValidRange($first, $last)) {
|
||||
throw new OutOfBoundsException("Invalid slot range $first-$last");
|
||||
}
|
||||
|
||||
return array_intersect_key($this->slots, array_fill($first, $last - $first + 1, null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the specified slot is assigned.
|
||||
*
|
||||
* @param int $slot Slot index.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function offsetExists($slot)
|
||||
{
|
||||
return isset($this->slots[$slot]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the node assigned to the specified slot.
|
||||
*
|
||||
* @param int $slot Slot index.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function offsetGet($slot)
|
||||
{
|
||||
return $this->slots[$slot] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns the specified slot to a node.
|
||||
*
|
||||
* @param int $slot Slot index.
|
||||
* @param NodeConnectionInterface|string $connection ID or connection instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function offsetSet($slot, $connection)
|
||||
{
|
||||
if (!static::isValid($slot)) {
|
||||
throw new OutOfBoundsException("Invalid slot $slot for `$connection`");
|
||||
}
|
||||
|
||||
$this->slots[(int) $slot] = (string) $connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the node assigned to the specified slot.
|
||||
*
|
||||
* @param int $slot Slot index.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function offsetUnset($slot)
|
||||
{
|
||||
unset($this->slots[$slot]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current number of assigned slots.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function count()
|
||||
{
|
||||
return count($this->slots);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator over the slot map.
|
||||
*
|
||||
* @return Traversable<int, string>
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function getIterator()
|
||||
{
|
||||
return new ArrayIterator($this->slots);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Argument;
|
||||
|
||||
/**
|
||||
* Allows to use object-oriented approach to handle complex conditional arguments.
|
||||
*/
|
||||
interface ArrayableArgument
|
||||
{
|
||||
/**
|
||||
* Get the instance as an array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array;
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Argument\Geospatial;
|
||||
|
||||
use UnexpectedValueException;
|
||||
|
||||
abstract class AbstractBy implements ByInterface
|
||||
{
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private static $unitEnum = ['m', 'km', 'ft', 'mi'];
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $unit;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
abstract public function toArray(): array;
|
||||
|
||||
/**
|
||||
* @param string $unit
|
||||
* @return void
|
||||
*/
|
||||
protected function setUnit(string $unit): void
|
||||
{
|
||||
if (!in_array($unit, self::$unitEnum, true)) {
|
||||
throw new UnexpectedValueException('Wrong value given for unit');
|
||||
}
|
||||
|
||||
$this->unit = $unit;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Argument\Geospatial;
|
||||
|
||||
class ByBox extends AbstractBy
|
||||
{
|
||||
private const KEYWORD = 'BYBOX';
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $width;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $height;
|
||||
|
||||
public function __construct(int $width, int $height, string $unit)
|
||||
{
|
||||
$this->width = $width;
|
||||
$this->height = $height;
|
||||
$this->setUnit($unit);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return [self::KEYWORD, $this->width, $this->height, $this->unit];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Argument\Geospatial;
|
||||
|
||||
use Predis\Command\Argument\ArrayableArgument;
|
||||
|
||||
interface ByInterface extends ArrayableArgument
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Argument\Geospatial;
|
||||
|
||||
class ByRadius extends AbstractBy
|
||||
{
|
||||
private const KEYWORD = 'BYRADIUS';
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $radius;
|
||||
|
||||
public function __construct(int $radius, string $unit)
|
||||
{
|
||||
$this->radius = $radius;
|
||||
$this->setUnit($unit);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return [self::KEYWORD, $this->radius, $this->unit];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Argument\Geospatial;
|
||||
|
||||
use Predis\Command\Argument\ArrayableArgument;
|
||||
|
||||
interface FromInterface extends ArrayableArgument
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Argument\Geospatial;
|
||||
|
||||
class FromLonLat implements FromInterface
|
||||
{
|
||||
private const KEYWORD = 'FROMLONLAT';
|
||||
|
||||
/**
|
||||
* @var float
|
||||
*/
|
||||
private $longitude;
|
||||
|
||||
/**
|
||||
* @var float
|
||||
*/
|
||||
private $latitude;
|
||||
|
||||
public function __construct(float $longitude, float $latitude)
|
||||
{
|
||||
$this->longitude = $longitude;
|
||||
$this->latitude = $latitude;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return [self::KEYWORD, $this->longitude, $this->latitude];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Argument\Geospatial;
|
||||
|
||||
class FromMember implements FromInterface
|
||||
{
|
||||
private const KEYWORD = 'FROMMEMBER';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $member;
|
||||
|
||||
public function __construct(string $member)
|
||||
{
|
||||
$this->member = $member;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return [self::KEYWORD, $this->member];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,161 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Argument\Search;
|
||||
|
||||
class AggregateArguments extends CommonArguments
|
||||
{
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private $sortingEnum = [
|
||||
'asc' => 'ASC',
|
||||
'desc' => 'DESC',
|
||||
];
|
||||
|
||||
/**
|
||||
* Loads document attributes from the source document.
|
||||
*
|
||||
* @param string ...$fields Could be just '*' to load all fields
|
||||
* @return $this
|
||||
*/
|
||||
public function load(string ...$fields): self
|
||||
{
|
||||
$arguments = func_get_args();
|
||||
|
||||
$this->arguments[] = 'LOAD';
|
||||
|
||||
if ($arguments[0] === '*') {
|
||||
$this->arguments[] = '*';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->arguments[] = count($arguments);
|
||||
$this->arguments = array_merge($this->arguments, $arguments);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads document attributes from the source document.
|
||||
*
|
||||
* @param string ...$properties
|
||||
* @return $this
|
||||
*/
|
||||
public function groupBy(string ...$properties): self
|
||||
{
|
||||
$arguments = func_get_args();
|
||||
|
||||
array_push($this->arguments, 'GROUPBY', count($arguments));
|
||||
$this->arguments = array_merge($this->arguments, $arguments);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Groups the results in the pipeline based on one or more properties.
|
||||
*
|
||||
* If you want to add alias property to your argument just add "true" value in arguments enumeration,
|
||||
* next value will be considered as alias to previous one.
|
||||
*
|
||||
* Example: 'argument', true, 'name' => 'argument' AS 'name'
|
||||
*
|
||||
* @param string $function
|
||||
* @param string|bool ...$argument
|
||||
* @return $this
|
||||
*/
|
||||
public function reduce(string $function, ...$argument): self
|
||||
{
|
||||
$arguments = func_get_args();
|
||||
$functionValue = array_shift($arguments);
|
||||
$argumentsCounter = 0;
|
||||
|
||||
for ($i = 0, $iMax = count($arguments); $i < $iMax; $i++) {
|
||||
if (true === $arguments[$i]) {
|
||||
$arguments[$i] = 'AS';
|
||||
$i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
$argumentsCounter++;
|
||||
}
|
||||
|
||||
array_push($this->arguments, 'REDUCE', $functionValue);
|
||||
$this->arguments = array_merge($this->arguments, [$argumentsCounter], $arguments);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the pipeline up until the point of SORTBY, using a list of properties.
|
||||
*
|
||||
* @param int $max
|
||||
* @param string ...$properties Enumeration of properties, including sorting direction (ASC, DESC)
|
||||
* @return $this
|
||||
*/
|
||||
public function sortBy(int $max = 0, ...$properties): self
|
||||
{
|
||||
$arguments = func_get_args();
|
||||
$maxValue = array_shift($arguments);
|
||||
|
||||
$this->arguments[] = 'SORTBY';
|
||||
$this->arguments = array_merge($this->arguments, [count($arguments)], $arguments);
|
||||
|
||||
if ($maxValue !== 0) {
|
||||
array_push($this->arguments, 'MAX', $maxValue);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies a 1-to-1 transformation on one or more properties and either stores the result
|
||||
* as a new property down the pipeline or replaces any property using this transformation.
|
||||
*
|
||||
* @param string $expression
|
||||
* @param string $as
|
||||
* @return $this
|
||||
*/
|
||||
public function apply(string $expression, string $as = ''): self
|
||||
{
|
||||
array_push($this->arguments, 'APPLY', $expression);
|
||||
|
||||
if ($as !== '') {
|
||||
array_push($this->arguments, 'AS', $as);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scan part of the results with a quicker alternative than LIMIT.
|
||||
*
|
||||
* @param int $readSize
|
||||
* @param int $idleTime
|
||||
* @return $this
|
||||
*/
|
||||
public function withCursor(int $readSize = 0, int $idleTime = 0): self
|
||||
{
|
||||
$this->arguments[] = 'WITHCURSOR';
|
||||
|
||||
if ($readSize !== 0) {
|
||||
array_push($this->arguments, 'COUNT', $readSize);
|
||||
}
|
||||
|
||||
if ($idleTime !== 0) {
|
||||
array_push($this->arguments, 'MAXIDLE', $idleTime);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Argument\Search;
|
||||
|
||||
class AlterArguments extends CommonArguments
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,182 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Argument\Search;
|
||||
|
||||
use Predis\Command\Argument\ArrayableArgument;
|
||||
|
||||
class CommonArguments implements ArrayableArgument
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $arguments = [];
|
||||
|
||||
/**
|
||||
* Adds default language for documents within an index.
|
||||
*
|
||||
* @param string $defaultLanguage
|
||||
* @return $this
|
||||
*/
|
||||
public function language(string $defaultLanguage = 'english'): self
|
||||
{
|
||||
$this->arguments[] = 'LANGUAGE';
|
||||
$this->arguments[] = $defaultLanguage;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects the dialect version under which to execute the query.
|
||||
* If not specified, the query will execute under the default dialect version
|
||||
* set during module initial loading or via FT.CONFIG SET command.
|
||||
*
|
||||
* @param string $dialect
|
||||
* @return $this
|
||||
*/
|
||||
public function dialect(string $dialect): self
|
||||
{
|
||||
$this->arguments[] = 'DIALECT';
|
||||
$this->arguments[] = $dialect;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* If set, does not scan and index.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function skipInitialScan(): self
|
||||
{
|
||||
$this->arguments[] = 'SKIPINITIALSCAN';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an arbitrary, binary safe payload that is exposed to custom scoring functions.
|
||||
*
|
||||
* @param string $payload
|
||||
* @return $this
|
||||
*/
|
||||
public function payload(string $payload): self
|
||||
{
|
||||
$this->arguments[] = 'PAYLOAD';
|
||||
$this->arguments[] = $payload;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Also returns the relative internal score of each document.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function withScores(): self
|
||||
{
|
||||
$this->arguments[] = 'WITHSCORES';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves optional document payloads.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function withPayloads(): self
|
||||
{
|
||||
$this->arguments[] = 'WITHPAYLOADS';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does not try to use stemming for query expansion but searches the query terms verbatim.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function verbatim(): self
|
||||
{
|
||||
$this->arguments[] = 'VERBATIM';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides the timeout parameter of the module.
|
||||
*
|
||||
* @param int $timeout
|
||||
* @return $this
|
||||
*/
|
||||
public function timeout(int $timeout): self
|
||||
{
|
||||
$this->arguments[] = 'TIMEOUT';
|
||||
$this->arguments[] = $timeout;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an arbitrary, binary safe payload that is exposed to custom scoring functions.
|
||||
*
|
||||
* @param int $offset
|
||||
* @param int $num
|
||||
* @return $this
|
||||
*/
|
||||
public function limit(int $offset, int $num): self
|
||||
{
|
||||
array_push($this->arguments, 'LIMIT', $offset, $num);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds filter expression into index.
|
||||
*
|
||||
* @param string $filter
|
||||
* @return $this
|
||||
*/
|
||||
public function filter(string $filter): self
|
||||
{
|
||||
$this->arguments[] = 'FILTER';
|
||||
$this->arguments[] = $filter;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines one or more value parameters. Each parameter has a name and a value.
|
||||
*
|
||||
* Example: ['name1', 'value1', 'name2', 'value2'...]
|
||||
*
|
||||
* @param array $nameValuesDictionary
|
||||
* @return $this
|
||||
*/
|
||||
public function params(array $nameValuesDictionary): self
|
||||
{
|
||||
$this->arguments[] = 'PARAMS';
|
||||
$this->arguments[] = count($nameValuesDictionary);
|
||||
$this->arguments = array_merge($this->arguments, $nameValuesDictionary);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return $this->arguments;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,191 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Argument\Search;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
class CreateArguments extends CommonArguments
|
||||
{
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private $supportedDataTypesEnum = [
|
||||
'hash' => 'HASH',
|
||||
'json' => 'JSON',
|
||||
];
|
||||
|
||||
/**
|
||||
* Specify data type for given index. To index JSON you must have the RedisJSON module to be installed.
|
||||
*
|
||||
* @param string $modifier
|
||||
* @return $this
|
||||
*/
|
||||
public function on(string $modifier = 'HASH'): self
|
||||
{
|
||||
if (in_array(strtoupper($modifier), $this->supportedDataTypesEnum)) {
|
||||
$this->arguments[] = 'ON';
|
||||
$this->arguments[] = $this->supportedDataTypesEnum[strtolower($modifier)];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
$enumValues = implode(', ', array_values($this->supportedDataTypesEnum));
|
||||
throw new InvalidArgumentException("Wrong modifier value given. Currently supports: {$enumValues}");
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds one or more prefixes into index.
|
||||
*
|
||||
* @param array $prefixes
|
||||
* @return $this
|
||||
*/
|
||||
public function prefix(array $prefixes): self
|
||||
{
|
||||
$this->arguments[] = 'PREFIX';
|
||||
$this->arguments[] = count($prefixes);
|
||||
$this->arguments = array_merge($this->arguments, $prefixes);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Document attribute set as document language.
|
||||
*
|
||||
* @param string $languageAttribute
|
||||
* @return $this
|
||||
*/
|
||||
public function languageField(string $languageAttribute): self
|
||||
{
|
||||
$this->arguments[] = 'LANGUAGE_FIELD';
|
||||
$this->arguments[] = $languageAttribute;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default score for documents in the index.
|
||||
*
|
||||
* @param float $defaultScore
|
||||
* @return $this
|
||||
*/
|
||||
public function score(float $defaultScore = 1.0): self
|
||||
{
|
||||
$this->arguments[] = 'SCORE';
|
||||
$this->arguments[] = $defaultScore;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Document attribute that used as the document rank based on the user ranking.
|
||||
*
|
||||
* @param string $scoreAttribute
|
||||
* @return $this
|
||||
*/
|
||||
public function scoreField(string $scoreAttribute): self
|
||||
{
|
||||
$this->arguments[] = 'SCORE_FIELD';
|
||||
$this->arguments[] = $scoreAttribute;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces RediSearch to encode indexes as if there were more than 32 text attributes.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function maxTextFields(): self
|
||||
{
|
||||
$this->arguments[] = 'MAXTEXTFIELDS';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does not store term offsets for documents.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function noOffsets(): self
|
||||
{
|
||||
$this->arguments[] = 'NOOFFSETS';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a lightweight temporary index that expires after a specified period of inactivity, in seconds.
|
||||
*
|
||||
* @param int $seconds
|
||||
* @return $this
|
||||
*/
|
||||
public function temporary(int $seconds): self
|
||||
{
|
||||
$this->arguments[] = 'TEMPORARY';
|
||||
$this->arguments[] = $seconds;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Conserves storage space and memory by disabling highlighting support.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function noHl(): self
|
||||
{
|
||||
$this->arguments[] = 'NOHL';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does not store attribute bits for each term.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function noFields(): self
|
||||
{
|
||||
$this->arguments[] = 'NOFIELDS';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Avoids saving the term frequencies in the index.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function noFreqs(): self
|
||||
{
|
||||
$this->arguments[] = 'NOFREQS';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the index with a custom stopword list, to be ignored during indexing and search time.
|
||||
*
|
||||
* @param array $stopWords
|
||||
* @return $this
|
||||
*/
|
||||
public function stopWords(array $stopWords): self
|
||||
{
|
||||
$this->arguments[] = 'STOPWORDS';
|
||||
$this->arguments[] = count($stopWords);
|
||||
$this->arguments = array_merge($this->arguments, $stopWords);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Argument\Search;
|
||||
|
||||
use Predis\Command\Argument\ArrayableArgument;
|
||||
|
||||
class CursorArguments implements ArrayableArgument
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $arguments = [];
|
||||
|
||||
/**
|
||||
* Is number of results to read. This parameter overrides COUNT specified in FT.AGGREGATE.
|
||||
*
|
||||
* @param int $readSize
|
||||
* @return $this
|
||||
*/
|
||||
public function count(int $readSize): self
|
||||
{
|
||||
array_push($this->arguments, 'COUNT', $readSize);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return $this->arguments;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Argument\Search;
|
||||
|
||||
use Predis\Command\Argument\ArrayableArgument;
|
||||
|
||||
class DropArguments implements ArrayableArgument
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $arguments = [];
|
||||
|
||||
/**
|
||||
* Drop operation that, if set, deletes the actual document hashes.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function dd(): self
|
||||
{
|
||||
$this->arguments[] = 'DD';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return $this->arguments;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Argument\Search;
|
||||
|
||||
class ExplainArguments extends CommonArguments
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Argument\Search;
|
||||
|
||||
use Predis\Command\Argument\ArrayableArgument;
|
||||
|
||||
class ProfileArguments implements ArrayableArgument
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $arguments = [];
|
||||
|
||||
/**
|
||||
* Adds search context.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function search(): self
|
||||
{
|
||||
$this->arguments[] = 'SEARCH';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds aggregate context.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function aggregate(): self
|
||||
{
|
||||
$this->arguments[] = 'AGGREGATE';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes details of reader iterator.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function limited(): self
|
||||
{
|
||||
$this->arguments[] = 'LIMITED';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is query string, as if sent to FT.SEARCH.
|
||||
*
|
||||
* @param string $query
|
||||
* @return $this
|
||||
*/
|
||||
public function query(string $query): self
|
||||
{
|
||||
$this->arguments[] = 'QUERY';
|
||||
$this->arguments[] = $query;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return $this->arguments;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Argument\Search\SchemaFields;
|
||||
|
||||
abstract class AbstractField implements FieldInterface
|
||||
{
|
||||
public const SORTABLE = true;
|
||||
public const NOT_SORTABLE = false;
|
||||
public const SORTABLE_UNF = 'UNF';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $fieldArguments = [];
|
||||
|
||||
/**
|
||||
* @param string $fieldType
|
||||
* @param string $identifier
|
||||
* @param string $alias
|
||||
* @param bool|string $sortable
|
||||
* @param bool $noIndex
|
||||
* @return void
|
||||
*/
|
||||
protected function setCommonOptions(
|
||||
string $fieldType,
|
||||
string $identifier,
|
||||
string $alias = '',
|
||||
$sortable = self::NOT_SORTABLE,
|
||||
bool $noIndex = false
|
||||
): void {
|
||||
$this->fieldArguments[] = $identifier;
|
||||
|
||||
if ($alias !== '') {
|
||||
$this->fieldArguments[] = 'AS';
|
||||
$this->fieldArguments[] = $alias;
|
||||
}
|
||||
|
||||
$this->fieldArguments[] = $fieldType;
|
||||
|
||||
if ($sortable === self::SORTABLE) {
|
||||
$this->fieldArguments[] = 'SORTABLE';
|
||||
} elseif ($sortable === self::SORTABLE_UNF) {
|
||||
$this->fieldArguments[] = 'SORTABLE';
|
||||
$this->fieldArguments[] = 'UNF';
|
||||
}
|
||||
|
||||
if ($noIndex) {
|
||||
$this->fieldArguments[] = 'NOINDEX';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return $this->fieldArguments;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Argument\Search\SchemaFields;
|
||||
|
||||
use Predis\Command\Argument\ArrayableArgument;
|
||||
|
||||
/**
|
||||
* Represents field in search schema.
|
||||
*/
|
||||
interface FieldInterface extends ArrayableArgument
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Argument\Search\SchemaFields;
|
||||
|
||||
class GeoField extends AbstractField
|
||||
{
|
||||
/**
|
||||
* @param string $identifier
|
||||
* @param string $alias
|
||||
* @param bool|string $sortable
|
||||
* @param bool $noIndex
|
||||
*/
|
||||
public function __construct(
|
||||
string $identifier,
|
||||
string $alias = '',
|
||||
$sortable = self::NOT_SORTABLE,
|
||||
bool $noIndex = false
|
||||
) {
|
||||
$this->setCommonOptions('GEO', $identifier, $alias, $sortable, $noIndex);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Argument\Search\SchemaFields;
|
||||
|
||||
class NumericField extends AbstractField
|
||||
{
|
||||
/**
|
||||
* @param string $identifier
|
||||
* @param string $alias
|
||||
* @param bool|string $sortable
|
||||
* @param bool $noIndex
|
||||
*/
|
||||
public function __construct(
|
||||
string $identifier,
|
||||
string $alias = '',
|
||||
$sortable = self::NOT_SORTABLE,
|
||||
bool $noIndex = false
|
||||
) {
|
||||
$this->setCommonOptions('NUMERIC', $identifier, $alias, $sortable, $noIndex);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Argument\Search\SchemaFields;
|
||||
|
||||
class TagField extends AbstractField
|
||||
{
|
||||
/**
|
||||
* @param string $identifier
|
||||
* @param string $alias
|
||||
* @param bool|string $sortable
|
||||
* @param bool $noIndex
|
||||
* @param string $separator
|
||||
* @param bool $caseSensitive
|
||||
*/
|
||||
public function __construct(
|
||||
string $identifier,
|
||||
string $alias = '',
|
||||
$sortable = self::NOT_SORTABLE,
|
||||
bool $noIndex = false,
|
||||
string $separator = ',',
|
||||
bool $caseSensitive = false
|
||||
) {
|
||||
$this->setCommonOptions('TAG', $identifier, $alias, $sortable, $noIndex);
|
||||
|
||||
if ($separator !== ',') {
|
||||
$this->fieldArguments[] = 'SEPARATOR';
|
||||
$this->fieldArguments[] = $separator;
|
||||
}
|
||||
|
||||
if ($caseSensitive) {
|
||||
$this->fieldArguments[] = 'CASESENSITIVE';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Argument\Search\SchemaFields;
|
||||
|
||||
class TextField extends AbstractField
|
||||
{
|
||||
/**
|
||||
* @param string $identifier
|
||||
* @param string $alias
|
||||
* @param bool|string $sortable
|
||||
* @param bool $noIndex
|
||||
* @param bool $noStem
|
||||
* @param string $phonetic
|
||||
* @param int $weight
|
||||
* @param bool $withSuffixTrie
|
||||
*/
|
||||
public function __construct(
|
||||
string $identifier,
|
||||
string $alias = '',
|
||||
$sortable = self::NOT_SORTABLE,
|
||||
bool $noIndex = false,
|
||||
bool $noStem = false,
|
||||
string $phonetic = '',
|
||||
int $weight = 1,
|
||||
bool $withSuffixTrie = false
|
||||
) {
|
||||
$this->setCommonOptions('TEXT', $identifier, $alias, $sortable, $noIndex);
|
||||
|
||||
if ($noStem) {
|
||||
$this->fieldArguments[] = 'NOSTEM';
|
||||
}
|
||||
|
||||
if ($phonetic !== '') {
|
||||
$this->fieldArguments[] = 'PHONETIC';
|
||||
$this->fieldArguments[] = $phonetic;
|
||||
}
|
||||
|
||||
if ($weight !== 1) {
|
||||
$this->fieldArguments[] = 'WEIGHT';
|
||||
$this->fieldArguments[] = $weight;
|
||||
}
|
||||
|
||||
if ($withSuffixTrie) {
|
||||
$this->fieldArguments[] = 'WITHSUFFIXTRIE';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Argument\Search\SchemaFields;
|
||||
|
||||
class VectorField extends AbstractField
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $fieldArguments = [];
|
||||
|
||||
/**
|
||||
* @param string $fieldName
|
||||
* @param string $algorithm
|
||||
* @param array $attributeNameValueDictionary
|
||||
* @param string $alias
|
||||
*/
|
||||
public function __construct(
|
||||
string $fieldName,
|
||||
string $algorithm,
|
||||
array $attributeNameValueDictionary,
|
||||
string $alias = ''
|
||||
) {
|
||||
$this->setCommonOptions('VECTOR', $fieldName, $alias);
|
||||
|
||||
array_push($this->fieldArguments, $algorithm, count($attributeNameValueDictionary));
|
||||
$this->fieldArguments = array_merge($this->fieldArguments, $attributeNameValueDictionary);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return $this->fieldArguments;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,306 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Argument\Search;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
class SearchArguments extends CommonArguments
|
||||
{
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private $sortingEnum = [
|
||||
'asc' => 'ASC',
|
||||
'desc' => 'DESC',
|
||||
];
|
||||
|
||||
/**
|
||||
* Returns the document ids and not the content.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function noContent(): self
|
||||
{
|
||||
$this->arguments[] = 'NOCONTENT';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of the sorting key, right after the id and score and/or payload, if requested.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function withSortKeys(): self
|
||||
{
|
||||
$this->arguments[] = 'WITHSORTKEYS';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Limits results to those having numeric values ranging between min and max,
|
||||
* if numeric_attribute is defined as a numeric attribute in FT.CREATE.
|
||||
* Min and max follow ZRANGE syntax, and can be -inf, +inf, and use( for exclusive ranges.
|
||||
* Multiple numeric filters for different attributes are supported in one query.
|
||||
*
|
||||
* @param array ...$filter Should contain: numeric_field, min and max. Example: ['numeric_field', 1, 10]
|
||||
* @return $this
|
||||
*/
|
||||
public function searchFilter(array ...$filter): self
|
||||
{
|
||||
$arguments = func_get_args();
|
||||
|
||||
foreach ($arguments as $argument) {
|
||||
array_push($this->arguments, 'FILTER', ...$argument);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the results to a given radius from lon and lat. Radius is given as a number and units.
|
||||
*
|
||||
* @param array ...$filter Should contain: geo_field, lon, lat, radius, unit. Example: ['geo_field', 34.1231, 35.1231, 300, km]
|
||||
* @return $this
|
||||
*/
|
||||
public function geoFilter(array ...$filter): self
|
||||
{
|
||||
$arguments = func_get_args();
|
||||
|
||||
foreach ($arguments as $argument) {
|
||||
array_push($this->arguments, 'GEOFILTER', ...$argument);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Limits the result to a given set of keys specified in the list.
|
||||
*
|
||||
* @param array $keys
|
||||
* @return $this
|
||||
*/
|
||||
public function inKeys(array $keys): self
|
||||
{
|
||||
$this->arguments[] = 'INKEYS';
|
||||
$this->arguments[] = count($keys);
|
||||
$this->arguments = array_merge($this->arguments, $keys);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the results to those appearing only in specific attributes of the document, like title or URL.
|
||||
*
|
||||
* @param array $fields
|
||||
* @return $this
|
||||
*/
|
||||
public function inFields(array $fields): self
|
||||
{
|
||||
$this->arguments[] = 'INFIELDS';
|
||||
$this->arguments[] = count($fields);
|
||||
$this->arguments = array_merge($this->arguments, $fields);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Limits the attributes returned from the document.
|
||||
* Num is the number of attributes following the keyword.
|
||||
* If num is 0, it acts like NOCONTENT.
|
||||
* Identifier is either an attribute name (for hashes and JSON) or a JSON Path expression (for JSON).
|
||||
* Property is an optional name used in the result. If not provided, the identifier is used in the result.
|
||||
*
|
||||
* If you want to add alias property to your identifier just add "true" value in identifier enumeration,
|
||||
* next value will be considered as alias to previous one.
|
||||
*
|
||||
* Example: 'identifier', true, 'property' => 'identifier' AS 'property'
|
||||
*
|
||||
* @param int $count
|
||||
* @param string|bool ...$identifier
|
||||
* @return $this
|
||||
*/
|
||||
public function addReturn(int $count, ...$identifier): self
|
||||
{
|
||||
$arguments = func_get_args();
|
||||
|
||||
$this->arguments[] = 'RETURN';
|
||||
|
||||
for ($i = 1, $iMax = count($arguments); $i < $iMax; $i++) {
|
||||
if (true === $arguments[$i]) {
|
||||
$arguments[$i] = 'AS';
|
||||
}
|
||||
}
|
||||
|
||||
$this->arguments = array_merge($this->arguments, $arguments);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns only the sections of the attribute that contain the matched text.
|
||||
*
|
||||
* @param array $fields
|
||||
* @param int $frags
|
||||
* @param int $len
|
||||
* @param string $separator
|
||||
* @return $this
|
||||
*/
|
||||
public function summarize(array $fields = [], int $frags = 0, int $len = 0, string $separator = ''): self
|
||||
{
|
||||
$this->arguments[] = 'SUMMARIZE';
|
||||
|
||||
if (!empty($fields)) {
|
||||
$this->arguments[] = 'FIELDS';
|
||||
$this->arguments[] = count($fields);
|
||||
$this->arguments = array_merge($this->arguments, $fields);
|
||||
}
|
||||
|
||||
if ($frags !== 0) {
|
||||
$this->arguments[] = 'FRAGS';
|
||||
$this->arguments[] = $frags;
|
||||
}
|
||||
|
||||
if ($len !== 0) {
|
||||
$this->arguments[] = 'LEN';
|
||||
$this->arguments[] = $len;
|
||||
}
|
||||
|
||||
if ($separator !== '') {
|
||||
$this->arguments[] = 'SEPARATOR';
|
||||
$this->arguments[] = $separator;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats occurrences of matched text.
|
||||
*
|
||||
* @param array $fields
|
||||
* @param string $openTag
|
||||
* @param string $closeTag
|
||||
* @return $this
|
||||
*/
|
||||
public function highlight(array $fields = [], string $openTag = '', string $closeTag = ''): self
|
||||
{
|
||||
$this->arguments[] = 'HIGHLIGHT';
|
||||
|
||||
if (!empty($fields)) {
|
||||
$this->arguments[] = 'FIELDS';
|
||||
$this->arguments[] = count($fields);
|
||||
$this->arguments = array_merge($this->arguments, $fields);
|
||||
}
|
||||
|
||||
if ($openTag !== '' && $closeTag !== '') {
|
||||
array_push($this->arguments, 'TAGS', $openTag, $closeTag);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows a maximum of N intervening number of unmatched offsets between phrase terms.
|
||||
* In other words, the slop for exact phrases is 0.
|
||||
*
|
||||
* @param int $slop
|
||||
* @return $this
|
||||
*/
|
||||
public function slop(int $slop): self
|
||||
{
|
||||
$this->arguments[] = 'SLOP';
|
||||
$this->arguments[] = $slop;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts the query terms in the same order in the document as in the query, regardless of the offsets between them.
|
||||
* Typically used in conjunction with SLOP.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function inOrder(): self
|
||||
{
|
||||
$this->arguments[] = 'INORDER';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses a custom query expander instead of the stemmer.
|
||||
*
|
||||
* @param string $expander
|
||||
* @return $this
|
||||
*/
|
||||
public function expander(string $expander): self
|
||||
{
|
||||
$this->arguments[] = 'EXPANDER';
|
||||
$this->arguments[] = $expander;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses a custom scoring function you define.
|
||||
*
|
||||
* @param string $scorer
|
||||
* @return $this
|
||||
*/
|
||||
public function scorer(string $scorer): self
|
||||
{
|
||||
$this->arguments[] = 'SCORER';
|
||||
$this->arguments[] = $scorer;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a textual description of how the scores were calculated.
|
||||
* Using this options requires the WITHSCORES option.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function explainScore(): self
|
||||
{
|
||||
$this->arguments[] = 'EXPLAINSCORE';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Orders the results by the value of this attribute.
|
||||
* This applies to both text and numeric attributes.
|
||||
* Attributes needed for SORTBY should be declared as SORTABLE in the index, in order to be available with very low latency.
|
||||
* Note that this adds memory overhead.
|
||||
*
|
||||
* @param string $sortAttribute
|
||||
* @param string $orderBy
|
||||
* @return $this
|
||||
*/
|
||||
public function sortBy(string $sortAttribute, string $orderBy = 'asc'): self
|
||||
{
|
||||
$this->arguments[] = 'SORTBY';
|
||||
$this->arguments[] = $sortAttribute;
|
||||
|
||||
if (in_array(strtoupper($orderBy), $this->sortingEnum)) {
|
||||
$this->arguments[] = $this->sortingEnum[strtolower($orderBy)];
|
||||
} else {
|
||||
$enumValues = implode(', ', array_values($this->sortingEnum));
|
||||
throw new InvalidArgumentException("Wrong order direction value given. Currently supports: {$enumValues}");
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Argument\Search;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
class SpellcheckArguments extends CommonArguments
|
||||
{
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private $termsEnum = [
|
||||
'include' => 'INCLUDE',
|
||||
'exclude' => 'EXCLUDE',
|
||||
];
|
||||
|
||||
/**
|
||||
* Is maximum Levenshtein distance for spelling suggestions (default: 1, max: 4).
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function distance(int $distance): self
|
||||
{
|
||||
$this->arguments[] = 'DISTANCE';
|
||||
$this->arguments[] = $distance;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies an inclusion (INCLUDE) or exclusion (EXCLUDE) of a custom dictionary named {dict}.
|
||||
*
|
||||
* @param string $dictionary
|
||||
* @param string $modifier
|
||||
* @param string ...$terms
|
||||
* @return $this
|
||||
*/
|
||||
public function terms(string $dictionary, string $modifier = 'INCLUDE', string ...$terms): self
|
||||
{
|
||||
if (!in_array(strtoupper($modifier), $this->termsEnum)) {
|
||||
$enumValues = implode(', ', array_values($this->termsEnum));
|
||||
throw new InvalidArgumentException("Wrong modifier value given. Currently supports: {$enumValues}");
|
||||
}
|
||||
|
||||
array_push($this->arguments, 'TERMS', $this->termsEnum[strtolower($modifier)], $dictionary, ...$terms);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Argument\Search;
|
||||
|
||||
class SugAddArguments extends CommonArguments
|
||||
{
|
||||
/**
|
||||
* Adds INCR modifier.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function incr(): self
|
||||
{
|
||||
$this->arguments[] = 'INCR';
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Argument\Search;
|
||||
|
||||
class SugGetArguments extends CommonArguments
|
||||
{
|
||||
/**
|
||||
* Performs a fuzzy prefix search, including prefixes at Levenshtein distance of 1 from the prefix sent.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function fuzzy(): self
|
||||
{
|
||||
$this->arguments[] = 'FUZZY';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Limits the results to a maximum of num (default: 5).
|
||||
*
|
||||
* @param int $num
|
||||
* @return $this
|
||||
*/
|
||||
public function max(int $num): self
|
||||
{
|
||||
array_push($this->arguments, 'MAX', $num);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Argument\Search;
|
||||
|
||||
class SynUpdateArguments extends CommonArguments
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Argument\Server;
|
||||
|
||||
use Predis\Command\Argument\ArrayableArgument;
|
||||
|
||||
interface LimitInterface extends ArrayableArgument
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Argument\Server;
|
||||
|
||||
class LimitOffsetCount implements LimitInterface
|
||||
{
|
||||
private const KEYWORD = 'LIMIT';
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $offset;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $count;
|
||||
|
||||
public function __construct(int $offset, int $count)
|
||||
{
|
||||
$this->offset = $offset;
|
||||
$this->count = $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return [self::KEYWORD, $this->offset, $this->count];
|
||||
}
|
||||
}
|
||||
57
plugins/cache-redis/Predis/Command/Argument/Server/To.php
Normal file
57
plugins/cache-redis/Predis/Command/Argument/Server/To.php
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Argument\Server;
|
||||
|
||||
use Predis\Command\Argument\ArrayableArgument;
|
||||
|
||||
class To implements ArrayableArgument
|
||||
{
|
||||
private const KEYWORD = 'TO';
|
||||
private const FORCE_KEYWORD = 'FORCE';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $host;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $port;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $isForce;
|
||||
|
||||
public function __construct(string $host, int $port, bool $isForce = false)
|
||||
{
|
||||
$this->host = $host;
|
||||
$this->port = $port;
|
||||
$this->isForce = $isForce;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
$arguments = [self::KEYWORD, $this->host, $this->port];
|
||||
|
||||
if ($this->isForce) {
|
||||
$arguments[] = self::FORCE_KEYWORD;
|
||||
}
|
||||
|
||||
return $arguments;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Argument\TimeSeries;
|
||||
|
||||
class AddArguments extends CommonArguments
|
||||
{
|
||||
/**
|
||||
* Is overwrite key and database configuration for DUPLICATE_POLICY,
|
||||
* the policy for handling samples with identical timestamps.
|
||||
*
|
||||
* @param string $policy
|
||||
* @return $this
|
||||
*/
|
||||
public function onDuplicate(string $policy = self::POLICY_BLOCK): self
|
||||
{
|
||||
array_push($this->arguments, 'ON_DUPLICATE', $policy);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Argument\TimeSeries;
|
||||
|
||||
class AlterArguments extends CommonArguments
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,143 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Argument\TimeSeries;
|
||||
|
||||
use Predis\Command\Argument\ArrayableArgument;
|
||||
|
||||
class CommonArguments implements ArrayableArgument
|
||||
{
|
||||
public const POLICY_BLOCK = 'BLOCK';
|
||||
public const POLICY_FIRST = 'FIRST';
|
||||
public const POLICY_LAST = 'LAST';
|
||||
public const POLICY_MIN = 'MIN';
|
||||
public const POLICY_MAX = 'MAX';
|
||||
public const POLICY_SUM = 'SUM';
|
||||
|
||||
public const ENCODING_UNCOMPRESSED = 'UNCOMPRESSED';
|
||||
public const ENCODING_COMPRESSED = 'COMPRESSED';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $arguments = [];
|
||||
|
||||
/**
|
||||
* Is maximum age for samples compared to the highest reported timestamp, in milliseconds.
|
||||
*
|
||||
* @param int $retentionPeriod
|
||||
* @return $this
|
||||
*/
|
||||
public function retentionMsecs(int $retentionPeriod): self
|
||||
{
|
||||
array_push($this->arguments, 'RETENTION', $retentionPeriod);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is initial allocation size, in bytes, for the data part of each new chunk.
|
||||
*
|
||||
* @param int $size
|
||||
* @return $this
|
||||
*/
|
||||
public function chunkSize(int $size): self
|
||||
{
|
||||
array_push($this->arguments, 'CHUNK_SIZE', $size);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is policy for handling insertion of multiple samples with identical timestamps.
|
||||
*
|
||||
* @param string $policy
|
||||
* @return $this
|
||||
*/
|
||||
public function duplicatePolicy(string $policy = self::POLICY_BLOCK): self
|
||||
{
|
||||
array_push($this->arguments, 'DUPLICATE_POLICY', $policy);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is set of label-value pairs that represent metadata labels of the key and serve as a secondary index.
|
||||
*
|
||||
* @param mixed ...$labelValuePair
|
||||
* @return $this
|
||||
*/
|
||||
public function labels(...$labelValuePair): self
|
||||
{
|
||||
array_push($this->arguments, 'LABELS', ...$labelValuePair);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the series samples encoding format.
|
||||
*
|
||||
* @param string $encoding
|
||||
* @return $this
|
||||
*/
|
||||
public function encoding(string $encoding = self::ENCODING_COMPRESSED): self
|
||||
{
|
||||
array_push($this->arguments, 'ENCODING', $encoding);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is used when a time series is a compaction.
|
||||
* With LATEST, TS.GET reports the compacted value of the latest, possibly partial, bucket.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function latest(): self
|
||||
{
|
||||
$this->arguments[] = 'LATEST';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Includes in the reply all label-value pairs representing metadata labels of the time series.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function withLabels(): self
|
||||
{
|
||||
$this->arguments[] = 'WITHLABELS';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a subset of the label-value pairs that represent metadata labels of the time series.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function selectedLabels(string ...$labels): self
|
||||
{
|
||||
array_push($this->arguments, 'SELECTED_LABELS', ...$labels);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return $this->arguments;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Argument\TimeSeries;
|
||||
|
||||
class CreateArguments extends CommonArguments
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Argument\TimeSeries;
|
||||
|
||||
class DecrByArguments extends IncrByArguments
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Argument\TimeSeries;
|
||||
|
||||
class GetArguments extends CommonArguments
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Argument\TimeSeries;
|
||||
|
||||
class IncrByArguments extends CommonArguments
|
||||
{
|
||||
/**
|
||||
* Is (integer) UNIX sample timestamp in milliseconds or * to set the timestamp according to the server clock.
|
||||
*
|
||||
* @param string|int $timeStamp
|
||||
* @return $this
|
||||
*/
|
||||
public function timestamp($timeStamp): self
|
||||
{
|
||||
array_push($this->arguments, 'TIMESTAMP', $timeStamp);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes data storage from compressed (default) to uncompressed.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function uncompressed(): self
|
||||
{
|
||||
$this->arguments[] = 'UNCOMPRESSED';
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Argument\TimeSeries;
|
||||
|
||||
use Predis\Command\Argument\ArrayableArgument;
|
||||
|
||||
class InfoArguments implements ArrayableArgument
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $arguments = [];
|
||||
|
||||
/**
|
||||
* Is an optional flag to get a more detailed information about the chunks.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function debug(): self
|
||||
{
|
||||
$this->arguments[] = 'DEBUG';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return $this->arguments;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Argument\TimeSeries;
|
||||
|
||||
class MGetArguments extends CommonArguments
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Argument\TimeSeries;
|
||||
|
||||
class MRangeArguments extends RangeArguments
|
||||
{
|
||||
/**
|
||||
* Filters time series based on their labels and label values.
|
||||
*
|
||||
* @param string ...$filterExpressions
|
||||
* @return $this
|
||||
*/
|
||||
public function filter(string ...$filterExpressions): self
|
||||
{
|
||||
array_push($this->arguments, 'FILTER', ...$filterExpressions);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits time series into groups, each group contains time series that share the same
|
||||
* value for the provided label name, then aggregates results in each group.
|
||||
*
|
||||
* @param string $label
|
||||
* @param string $reducer
|
||||
* @return $this
|
||||
*/
|
||||
public function groupBy(string $label, string $reducer): self
|
||||
{
|
||||
array_push($this->arguments, 'GROUPBY', $label, 'REDUCE', $reducer);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Argument\TimeSeries;
|
||||
|
||||
class RangeArguments extends CommonArguments
|
||||
{
|
||||
/**
|
||||
* Filters samples by a list of specific timestamps.
|
||||
*
|
||||
* @param int ...$ts
|
||||
* @return $this
|
||||
*/
|
||||
public function filterByTs(int ...$ts): self
|
||||
{
|
||||
array_push($this->arguments, 'FILTER_BY_TS', ...$ts);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters samples by minimum and maximum values.
|
||||
*
|
||||
* @param int $min
|
||||
* @param int $max
|
||||
* @return $this
|
||||
*/
|
||||
public function filterByValue(int $min, int $max): self
|
||||
{
|
||||
array_push($this->arguments, 'FILTER_BY_VALUE', $min, $max);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Limits the number of returned samples.
|
||||
*
|
||||
* @param int $count
|
||||
* @return $this
|
||||
*/
|
||||
public function count(int $count): self
|
||||
{
|
||||
array_push($this->arguments, 'COUNT', $count);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Aggregates samples into time buckets.
|
||||
*
|
||||
* @param string $aggregator
|
||||
* @param int $bucketDuration Is duration of each bucket, in milliseconds.
|
||||
* @param int $align It controls the time bucket timestamps by changing the reference timestamp on which a bucket is defined.
|
||||
* @param int $bucketTimestamp Controls how bucket timestamps are reported.
|
||||
* @param bool $empty Is a flag, which, when specified, reports aggregations also for empty buckets.
|
||||
* @return $this
|
||||
*/
|
||||
public function aggregation(string $aggregator, int $bucketDuration, int $align = 0, int $bucketTimestamp = 0, bool $empty = false): self
|
||||
{
|
||||
if ($align > 0) {
|
||||
array_push($this->arguments, 'ALIGN', $align);
|
||||
}
|
||||
|
||||
array_push($this->arguments, 'AGGREGATION', $aggregator, $bucketDuration);
|
||||
|
||||
if ($bucketTimestamp > 0) {
|
||||
array_push($this->arguments, 'BUCKETTIMESTAMP', $bucketTimestamp);
|
||||
}
|
||||
|
||||
if (true === $empty) {
|
||||
$this->arguments[] = 'EMPTY';
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
143
plugins/cache-redis/Predis/Command/Factory.php
Normal file
143
plugins/cache-redis/Predis/Command/Factory.php
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Predis\ClientException;
|
||||
use Predis\Command\Processor\ProcessorInterface;
|
||||
|
||||
/**
|
||||
* Base command factory class.
|
||||
*
|
||||
* This class provides all of the common functionalities required for a command
|
||||
* factory to create new instances of Redis commands objects. It also allows to
|
||||
* define or undefine command handler classes for each command ID.
|
||||
*/
|
||||
abstract class Factory implements FactoryInterface
|
||||
{
|
||||
protected $commands = [];
|
||||
protected $processor;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function supports(string ...$commandIDs): bool
|
||||
{
|
||||
foreach ($commandIDs as $commandID) {
|
||||
if ($this->getCommandClass($commandID) === null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the FQCN of a class that represents the specified command ID.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param string $commandID Command ID
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getCommandClass(string $commandID): ?string
|
||||
{
|
||||
return $this->commands[strtoupper($commandID)] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function create(string $commandID, array $arguments = []): CommandInterface
|
||||
{
|
||||
if (!$commandClass = $this->getCommandClass($commandID)) {
|
||||
$commandID = strtoupper($commandID);
|
||||
|
||||
throw new ClientException("Command `$commandID` is not a registered Redis command.");
|
||||
}
|
||||
|
||||
$command = new $commandClass();
|
||||
$command->setArguments($arguments);
|
||||
|
||||
if (isset($this->processor)) {
|
||||
$this->processor->process($command);
|
||||
}
|
||||
|
||||
return $command;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines a command in the factory.
|
||||
*
|
||||
* Only classes implementing Predis\Command\CommandInterface are allowed to
|
||||
* handle a command. If the command specified by its ID is already handled
|
||||
* by the factory, the underlying command class is replaced by the new one.
|
||||
*
|
||||
* @param string $commandID Command ID
|
||||
* @param string $commandClass FQCN of a class implementing Predis\Command\CommandInterface
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function define(string $commandID, string $commandClass): void
|
||||
{
|
||||
if (!is_a($commandClass, 'Predis\Command\CommandInterface', true)) {
|
||||
throw new InvalidArgumentException(
|
||||
"Class $commandClass must implement Predis\Command\CommandInterface"
|
||||
);
|
||||
}
|
||||
|
||||
$this->commands[strtoupper($commandID)] = $commandClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Undefines a command in the factory.
|
||||
*
|
||||
* When the factory already has a class handler associated to the specified
|
||||
* command ID it is removed from the map of known commands. Nothing happens
|
||||
* when the command is not handled by the factory.
|
||||
*
|
||||
* @param string $commandID Command ID
|
||||
*/
|
||||
public function undefine(string $commandID): void
|
||||
{
|
||||
unset($this->commands[strtoupper($commandID)]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a command processor for processing command arguments.
|
||||
*
|
||||
* Command processors are used to process and transform arguments of Redis
|
||||
* commands before their newly created instances are returned to the caller
|
||||
* of "create()".
|
||||
*
|
||||
* A NULL value can be used to effectively unset any processor if previously
|
||||
* set for the command factory.
|
||||
*
|
||||
* @param ProcessorInterface|null $processor Command processor or NULL value.
|
||||
*/
|
||||
public function setProcessor(?ProcessorInterface $processor): void
|
||||
{
|
||||
$this->processor = $processor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current command processor.
|
||||
*
|
||||
* @return ProcessorInterface|null
|
||||
*/
|
||||
public function getProcessor(): ?ProcessorInterface
|
||||
{
|
||||
return $this->processor;
|
||||
}
|
||||
}
|
||||
42
plugins/cache-redis/Predis/Command/FactoryInterface.php
Normal file
42
plugins/cache-redis/Predis/Command/FactoryInterface.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command;
|
||||
|
||||
/**
|
||||
* Command factory interface.
|
||||
*
|
||||
* A command factory is used through the library to create instances of commands
|
||||
* classes implementing Predis\Command\CommandInterface mapped to Redis commands
|
||||
* by their command ID string (SET, GET, etc...).
|
||||
*/
|
||||
interface FactoryInterface
|
||||
{
|
||||
/**
|
||||
* Checks if the command factory supports the specified list of commands.
|
||||
*
|
||||
* @param string ...$commandIDs List of command IDs
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function supports(string ...$commandIDs): bool;
|
||||
|
||||
/**
|
||||
* Creates a new command instance.
|
||||
*
|
||||
* @param string $commandID Command ID
|
||||
* @param array $arguments Arguments for the command
|
||||
*
|
||||
* @return CommandInterface
|
||||
*/
|
||||
public function create(string $commandID, array $arguments = []): CommandInterface;
|
||||
}
|
||||
43
plugins/cache-redis/Predis/Command/RawFactory.php
Normal file
43
plugins/cache-redis/Predis/Command/RawFactory.php
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command;
|
||||
|
||||
/**
|
||||
* Command factory creating raw command instances out of command IDs.
|
||||
*
|
||||
* Any command ID will produce a command instance even for unknown commands that
|
||||
* are not implemented by Redis (the server will return a "-ERR unknown command"
|
||||
* error responses).
|
||||
*
|
||||
* When using this factory the client does not process arguments before sending
|
||||
* commands to Redis and server responses are not further processed before being
|
||||
* returned to the caller.
|
||||
*/
|
||||
class RawFactory implements FactoryInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function supports(string ...$commandIDs): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function create(string $commandID, array $arguments = []): CommandInterface
|
||||
{
|
||||
return new RawCommand($commandID, $arguments);
|
||||
}
|
||||
}
|
||||
53
plugins/cache-redis/Predis/Command/Redis/ACL.php
Normal file
53
plugins/cache-redis/Predis/Command/Redis/ACL.php
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis;
|
||||
|
||||
use Predis\Command\Command as RedisCommand;
|
||||
|
||||
/**
|
||||
* @see https://redis.io/commands/?name=ACL
|
||||
*
|
||||
* Container command corresponds to any ACL *.
|
||||
* Represents any ACL command with subcommand as first argument.
|
||||
*/
|
||||
class ACL extends RedisCommand
|
||||
{
|
||||
public function getId()
|
||||
{
|
||||
return 'ACL';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function parseResponse($data)
|
||||
{
|
||||
if (!is_array($data)) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
if ($data === array_values($data)) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
// flatten Relay (RESP3) maps
|
||||
$return = [];
|
||||
|
||||
array_walk($data, function ($value, $key) use (&$return) {
|
||||
$return[] = $key;
|
||||
$return[] = $value;
|
||||
});
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
29
plugins/cache-redis/Predis/Command/Redis/APPEND.php
Normal file
29
plugins/cache-redis/Predis/Command/Redis/APPEND.php
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis;
|
||||
|
||||
use Predis\Command\Command as RedisCommand;
|
||||
|
||||
/**
|
||||
* @see http://redis.io/commands/append
|
||||
*/
|
||||
class APPEND extends RedisCommand
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return 'APPEND';
|
||||
}
|
||||
}
|
||||
29
plugins/cache-redis/Predis/Command/Redis/AUTH.php
Normal file
29
plugins/cache-redis/Predis/Command/Redis/AUTH.php
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis;
|
||||
|
||||
use Predis\Command\Command as RedisCommand;
|
||||
|
||||
/**
|
||||
* @see http://redis.io/commands/auth
|
||||
*/
|
||||
class AUTH extends RedisCommand
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return 'AUTH';
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis\AbstractCommand;
|
||||
|
||||
use Predis\Command\Command as RedisCommand;
|
||||
use Predis\Command\Traits\Keys;
|
||||
|
||||
abstract class BZPOPBase extends RedisCommand
|
||||
{
|
||||
use Keys {
|
||||
Keys::setArguments as setKeys;
|
||||
}
|
||||
|
||||
protected static $keysArgumentPositionOffset = 0;
|
||||
|
||||
abstract public function getId(): string;
|
||||
|
||||
public function setArguments(array $arguments)
|
||||
{
|
||||
$this->setKeys($arguments, false);
|
||||
}
|
||||
|
||||
public function parseResponse($data)
|
||||
{
|
||||
$key = array_shift($data);
|
||||
|
||||
if (null === $key) {
|
||||
return [$key];
|
||||
}
|
||||
|
||||
return array_combine([$key], [[$data[0] => $data[1]]]);
|
||||
}
|
||||
}
|
||||
37
plugins/cache-redis/Predis/Command/Redis/BGREWRITEAOF.php
Normal file
37
plugins/cache-redis/Predis/Command/Redis/BGREWRITEAOF.php
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis;
|
||||
|
||||
use Predis\Command\Command as RedisCommand;
|
||||
|
||||
/**
|
||||
* @see http://redis.io/commands/bgrewriteaof
|
||||
*/
|
||||
class BGREWRITEAOF extends RedisCommand
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return 'BGREWRITEAOF';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function parseResponse($data)
|
||||
{
|
||||
return $data == 'Background append only file rewriting started';
|
||||
}
|
||||
}
|
||||
37
plugins/cache-redis/Predis/Command/Redis/BGSAVE.php
Normal file
37
plugins/cache-redis/Predis/Command/Redis/BGSAVE.php
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis;
|
||||
|
||||
use Predis\Command\Command as RedisCommand;
|
||||
|
||||
/**
|
||||
* @see http://redis.io/commands/bgsave
|
||||
*/
|
||||
class BGSAVE extends RedisCommand
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return 'BGSAVE';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function parseResponse($data)
|
||||
{
|
||||
return $data === 'Background saving started' ? true : $data;
|
||||
}
|
||||
}
|
||||
34
plugins/cache-redis/Predis/Command/Redis/BITCOUNT.php
Normal file
34
plugins/cache-redis/Predis/Command/Redis/BITCOUNT.php
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis;
|
||||
|
||||
use Predis\Command\Command as RedisCommand;
|
||||
use Predis\Command\Traits\BitByte;
|
||||
|
||||
/**
|
||||
* @see http://redis.io/commands/bitcount
|
||||
*
|
||||
* Count the number of set bits (population counting) in a string.
|
||||
*/
|
||||
class BITCOUNT extends RedisCommand
|
||||
{
|
||||
use BitByte;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return 'BITCOUNT';
|
||||
}
|
||||
}
|
||||
29
plugins/cache-redis/Predis/Command/Redis/BITFIELD.php
Normal file
29
plugins/cache-redis/Predis/Command/Redis/BITFIELD.php
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis;
|
||||
|
||||
use Predis\Command\Command as RedisCommand;
|
||||
|
||||
/**
|
||||
* @see http://redis.io/commands/bitfield
|
||||
*/
|
||||
class BITFIELD extends RedisCommand
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return 'BITFIELD';
|
||||
}
|
||||
}
|
||||
43
plugins/cache-redis/Predis/Command/Redis/BITOP.php
Normal file
43
plugins/cache-redis/Predis/Command/Redis/BITOP.php
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis;
|
||||
|
||||
use Predis\Command\Command as RedisCommand;
|
||||
|
||||
/**
|
||||
* @see http://redis.io/commands/bitop
|
||||
*/
|
||||
class BITOP extends RedisCommand
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return 'BITOP';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setArguments(array $arguments)
|
||||
{
|
||||
if (count($arguments) === 3 && is_array($arguments[2])) {
|
||||
[$operation, $destination] = $arguments;
|
||||
$arguments = $arguments[2];
|
||||
array_unshift($arguments, $operation, $destination);
|
||||
}
|
||||
|
||||
parent::setArguments($arguments);
|
||||
}
|
||||
}
|
||||
34
plugins/cache-redis/Predis/Command/Redis/BITPOS.php
Normal file
34
plugins/cache-redis/Predis/Command/Redis/BITPOS.php
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis;
|
||||
|
||||
use Predis\Command\Command as RedisCommand;
|
||||
use Predis\Command\Traits\BitByte;
|
||||
|
||||
/**
|
||||
* @see http://redis.io/commands/bitpos
|
||||
*
|
||||
* Return the position of the first bit set to 1 or 0 in a string.
|
||||
*/
|
||||
class BITPOS extends RedisCommand
|
||||
{
|
||||
use BitByte;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return 'BITPOS';
|
||||
}
|
||||
}
|
||||
21
plugins/cache-redis/Predis/Command/Redis/BLMOVE.php
Normal file
21
plugins/cache-redis/Predis/Command/Redis/BLMOVE.php
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis;
|
||||
|
||||
class BLMOVE extends LMOVE
|
||||
{
|
||||
public function getId()
|
||||
{
|
||||
return 'BLMOVE';
|
||||
}
|
||||
}
|
||||
25
plugins/cache-redis/Predis/Command/Redis/BLMPOP.php
Normal file
25
plugins/cache-redis/Predis/Command/Redis/BLMPOP.php
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis;
|
||||
|
||||
class BLMPOP extends LMPOP
|
||||
{
|
||||
protected static $keysArgumentPositionOffset = 1;
|
||||
protected static $leftRightArgumentPositionOffset = 2;
|
||||
protected static $countArgumentPositionOffset = 3;
|
||||
|
||||
public function getId()
|
||||
{
|
||||
return 'BLMPOP';
|
||||
}
|
||||
}
|
||||
42
plugins/cache-redis/Predis/Command/Redis/BLPOP.php
Normal file
42
plugins/cache-redis/Predis/Command/Redis/BLPOP.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis;
|
||||
|
||||
use Predis\Command\Command as RedisCommand;
|
||||
|
||||
/**
|
||||
* @see http://redis.io/commands/blpop
|
||||
*/
|
||||
class BLPOP extends RedisCommand
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return 'BLPOP';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setArguments(array $arguments)
|
||||
{
|
||||
if (count($arguments) === 2 && is_array($arguments[0])) {
|
||||
[$arguments, $timeout] = $arguments;
|
||||
array_push($arguments, $timeout);
|
||||
}
|
||||
|
||||
parent::setArguments($arguments);
|
||||
}
|
||||
}
|
||||
42
plugins/cache-redis/Predis/Command/Redis/BRPOP.php
Normal file
42
plugins/cache-redis/Predis/Command/Redis/BRPOP.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis;
|
||||
|
||||
use Predis\Command\Command as RedisCommand;
|
||||
|
||||
/**
|
||||
* @see http://redis.io/commands/brpop
|
||||
*/
|
||||
class BRPOP extends RedisCommand
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return 'BRPOP';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setArguments(array $arguments)
|
||||
{
|
||||
if (count($arguments) === 2 && is_array($arguments[0])) {
|
||||
[$arguments, $timeout] = $arguments;
|
||||
array_push($arguments, $timeout);
|
||||
}
|
||||
|
||||
parent::setArguments($arguments);
|
||||
}
|
||||
}
|
||||
29
plugins/cache-redis/Predis/Command/Redis/BRPOPLPUSH.php
Normal file
29
plugins/cache-redis/Predis/Command/Redis/BRPOPLPUSH.php
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis;
|
||||
|
||||
use Predis\Command\Command as RedisCommand;
|
||||
|
||||
/**
|
||||
* @see http://redis.io/commands/brpoplpush
|
||||
*/
|
||||
class BRPOPLPUSH extends RedisCommand
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return 'BRPOPLPUSH';
|
||||
}
|
||||
}
|
||||
30
plugins/cache-redis/Predis/Command/Redis/BZMPOP.php
Normal file
30
plugins/cache-redis/Predis/Command/Redis/BZMPOP.php
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis;
|
||||
|
||||
/**
|
||||
* @see https://redis.io/commands/bzmpop/
|
||||
*
|
||||
* BZMPOP is the blocking variant of ZMPOP.
|
||||
*/
|
||||
class BZMPOP extends ZMPOP
|
||||
{
|
||||
protected static $keysArgumentPositionOffset = 1;
|
||||
protected static $countArgumentPositionOffset = 3;
|
||||
protected static $modifierArgumentPositionOffset = 2;
|
||||
|
||||
public function getId()
|
||||
{
|
||||
return 'BZMPOP';
|
||||
}
|
||||
}
|
||||
33
plugins/cache-redis/Predis/Command/Redis/BZPOPMAX.php
Normal file
33
plugins/cache-redis/Predis/Command/Redis/BZPOPMAX.php
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis;
|
||||
|
||||
use Predis\Command\Redis\AbstractCommand\BZPOPBase;
|
||||
|
||||
/**
|
||||
* @see https://redis.io/commands/bzpopmax/
|
||||
*
|
||||
* BZPOPMAX is the blocking variant of the sorted set ZPOPMAX primitive.
|
||||
*
|
||||
* It is the blocking version because it blocks the connection when there are
|
||||
* no members to pop from any of the given sorted sets.
|
||||
* A member with the highest score is popped from first sorted set that is non-empty,
|
||||
* with the given keys being checked in the order that they are given.
|
||||
*/
|
||||
class BZPOPMAX extends BZPOPBase
|
||||
{
|
||||
public function getId(): string
|
||||
{
|
||||
return 'BZPOPMAX';
|
||||
}
|
||||
}
|
||||
33
plugins/cache-redis/Predis/Command/Redis/BZPOPMIN.php
Normal file
33
plugins/cache-redis/Predis/Command/Redis/BZPOPMIN.php
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis;
|
||||
|
||||
use Predis\Command\Redis\AbstractCommand\BZPOPBase;
|
||||
|
||||
/**
|
||||
* @see https://redis.io/commands/bzpopmin/
|
||||
*
|
||||
* BZPOPMIN is the blocking variant of the sorted set ZPOPMIN primitive.
|
||||
*
|
||||
* It is the blocking version because it blocks the connection when there are
|
||||
* no members to pop from any of the given sorted sets.
|
||||
* A member with the lowest score is popped from first sorted set that is non-empty,
|
||||
* with the given keys being checked in the order that they are given.
|
||||
*/
|
||||
class BZPOPMIN extends BZPOPBase
|
||||
{
|
||||
public function getId(): string
|
||||
{
|
||||
return 'BZPOPMIN';
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis\BloomFilter;
|
||||
|
||||
use Predis\Command\Command as RedisCommand;
|
||||
|
||||
/**
|
||||
* @see https://redis.io/commands/bf.add/
|
||||
*
|
||||
* Creates an empty Bloom Filter with a single sub-filter for the
|
||||
* initial capacity requested and with an upper bound error_rate.
|
||||
*/
|
||||
class BFADD extends RedisCommand
|
||||
{
|
||||
public function getId()
|
||||
{
|
||||
return 'BF.ADD';
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis\BloomFilter;
|
||||
|
||||
use Predis\Command\Command as RedisCommand;
|
||||
|
||||
/**
|
||||
* @see https://redis.io/commands/bf.exists/
|
||||
*
|
||||
* Determines whether an item may exist in the Bloom Filter or not.
|
||||
*/
|
||||
class BFEXISTS extends RedisCommand
|
||||
{
|
||||
public function getId()
|
||||
{
|
||||
return 'BF.EXISTS';
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis\BloomFilter;
|
||||
|
||||
use Predis\Command\Command as RedisCommand;
|
||||
use UnexpectedValueException;
|
||||
|
||||
/**
|
||||
* @see https://redis.io/commands/bf.info/
|
||||
*
|
||||
* Return information about key filter.
|
||||
*/
|
||||
class BFINFO extends RedisCommand
|
||||
{
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private $modifierEnum = [
|
||||
'capacity' => 'CAPACITY',
|
||||
'size' => 'SIZE',
|
||||
'filters' => 'FILTERS',
|
||||
'items' => 'ITEMS',
|
||||
'expansion' => 'EXPANSION',
|
||||
];
|
||||
|
||||
public function getId()
|
||||
{
|
||||
return 'BF.INFO';
|
||||
}
|
||||
|
||||
public function setArguments(array $arguments)
|
||||
{
|
||||
if (isset($arguments[1])) {
|
||||
$modifier = array_pop($arguments);
|
||||
|
||||
if ($modifier === '') {
|
||||
parent::setArguments($arguments);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!in_array(strtoupper($modifier), $this->modifierEnum)) {
|
||||
$enumValues = implode(', ', array_keys($this->modifierEnum));
|
||||
throw new UnexpectedValueException("Argument accepts only: {$enumValues} values");
|
||||
}
|
||||
|
||||
$arguments[] = $this->modifierEnum[strtolower($modifier)];
|
||||
}
|
||||
|
||||
parent::setArguments($arguments);
|
||||
}
|
||||
|
||||
public function parseResponse($data)
|
||||
{
|
||||
if (count($data) > 1) {
|
||||
$result = [];
|
||||
|
||||
for ($i = 0, $iMax = count($data); $i < $iMax; ++$i) {
|
||||
if (array_key_exists($i + 1, $data)) {
|
||||
$result[(string) $data[$i]] = $data[++$i];
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis\BloomFilter;
|
||||
|
||||
use Predis\Command\Command as RedisCommand;
|
||||
use Predis\Command\Traits\BloomFilters\Capacity;
|
||||
use Predis\Command\Traits\BloomFilters\Error;
|
||||
use Predis\Command\Traits\BloomFilters\Expansion;
|
||||
use Predis\Command\Traits\BloomFilters\Items;
|
||||
use Predis\Command\Traits\BloomFilters\NoCreate;
|
||||
|
||||
class BFINSERT extends RedisCommand
|
||||
{
|
||||
use Capacity {
|
||||
Capacity::setArguments as setCapacity;
|
||||
}
|
||||
use Error {
|
||||
Error::setArguments as setErrorRate;
|
||||
}
|
||||
use Expansion {
|
||||
Expansion::setArguments as setExpansion;
|
||||
}
|
||||
use Items {
|
||||
Items::setArguments as setItems;
|
||||
}
|
||||
use NoCreate {
|
||||
NoCreate::setArguments as setNoCreate;
|
||||
}
|
||||
|
||||
protected static $capacityArgumentPositionOffset = 1;
|
||||
protected static $errorArgumentPositionOffset = 2;
|
||||
protected static $expansionArgumentPositionOffset = 3;
|
||||
protected static $noCreateArgumentPositionOffset = 4;
|
||||
protected static $itemsArgumentPositionOffset = 6;
|
||||
|
||||
public function getId()
|
||||
{
|
||||
return 'BF.INSERT';
|
||||
}
|
||||
|
||||
public function setArguments(array $arguments)
|
||||
{
|
||||
$this->setNoCreate($arguments);
|
||||
$arguments = $this->getArguments();
|
||||
|
||||
if (array_key_exists(5, $arguments) && $arguments[5]) {
|
||||
$arguments[5] = 'NONSCALING';
|
||||
}
|
||||
|
||||
$this->setItems($arguments);
|
||||
$arguments = $this->getArguments();
|
||||
|
||||
$this->setExpansion($arguments);
|
||||
$arguments = $this->getArguments();
|
||||
|
||||
$this->setErrorRate($arguments);
|
||||
$arguments = $this->getArguments();
|
||||
|
||||
$this->setCapacity($arguments);
|
||||
$this->filterArguments();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis\BloomFilter;
|
||||
|
||||
use Predis\Command\Command as RedisCommand;
|
||||
|
||||
/**
|
||||
* @see https://redis.io/commands/bf.loadchunk/
|
||||
*
|
||||
* Restores a filter previously saved using SCANDUMP. See the SCANDUMP command for example usage.
|
||||
*/
|
||||
class BFLOADCHUNK extends RedisCommand
|
||||
{
|
||||
public function getId()
|
||||
{
|
||||
return 'BF.LOADCHUNK';
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis\BloomFilter;
|
||||
|
||||
use Predis\Command\Command as RedisCommand;
|
||||
|
||||
/**
|
||||
* @see https://redis.io/commands/bf.madd/
|
||||
*
|
||||
* Adds one or more items to the Bloom Filter and creates the filter if it does not exist yet.
|
||||
* This command operates identically to BF.ADD except that it allows multiple inputs and returns multiple values.
|
||||
*/
|
||||
class BFMADD extends RedisCommand
|
||||
{
|
||||
public function getId()
|
||||
{
|
||||
return 'BF.MADD';
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis\BloomFilter;
|
||||
|
||||
use Predis\Command\Command as RedisCommand;
|
||||
|
||||
/**
|
||||
* @see https://redis.io/commands/bf.mexists/
|
||||
*
|
||||
* Determines if one or more items may exist in the filter or not.
|
||||
*/
|
||||
class BFMEXISTS extends RedisCommand
|
||||
{
|
||||
public function getId()
|
||||
{
|
||||
return 'BF.MEXISTS';
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis\BloomFilter;
|
||||
|
||||
use Predis\Command\Command as RedisCommand;
|
||||
use Predis\Command\Traits\BloomFilters\Expansion;
|
||||
|
||||
/**
|
||||
* @see https://redis.io/commands/bf.reserve/
|
||||
*
|
||||
* Creates an empty Bloom Filter with a single sub-filter for the initial capacity
|
||||
* requested and with an upper bound error_rate.
|
||||
*
|
||||
* By default, the filter auto-scales by creating additional sub-filters when capacity is reached.
|
||||
* The new sub-filter is created with size of the previous sub-filter multiplied by expansion.
|
||||
*/
|
||||
class BFRESERVE extends RedisCommand
|
||||
{
|
||||
use Expansion {
|
||||
Expansion::setArguments as setExpansion;
|
||||
}
|
||||
|
||||
protected static $expansionArgumentPositionOffset = 3;
|
||||
|
||||
public function getId()
|
||||
{
|
||||
return 'BF.RESERVE';
|
||||
}
|
||||
|
||||
public function setArguments(array $arguments)
|
||||
{
|
||||
if (array_key_exists(4, $arguments) && $arguments[4]) {
|
||||
$arguments[4] = 'NONSCALING';
|
||||
}
|
||||
|
||||
$this->setExpansion($arguments);
|
||||
$this->filterArguments();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis\BloomFilter;
|
||||
|
||||
use Predis\Command\Command as RedisCommand;
|
||||
|
||||
/**
|
||||
* @see https://redis.io/commands/bf.scandump/
|
||||
*
|
||||
* Begins an incremental save of the bloom filter.
|
||||
* This is useful for large bloom filters which cannot fit into the normal DUMP and RESTORE model.
|
||||
*/
|
||||
class BFSCANDUMP extends RedisCommand
|
||||
{
|
||||
public function getId()
|
||||
{
|
||||
return 'BF.SCANDUMP';
|
||||
}
|
||||
}
|
||||
75
plugins/cache-redis/Predis/Command/Redis/CLIENT.php
Normal file
75
plugins/cache-redis/Predis/Command/Redis/CLIENT.php
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis;
|
||||
|
||||
use Predis\Command\Command as RedisCommand;
|
||||
|
||||
/**
|
||||
* @see http://redis.io/commands/client-list
|
||||
* @see http://redis.io/commands/client-kill
|
||||
* @see http://redis.io/commands/client-getname
|
||||
* @see http://redis.io/commands/client-setname
|
||||
*/
|
||||
class CLIENT extends RedisCommand
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return 'CLIENT';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function parseResponse($data)
|
||||
{
|
||||
$args = array_change_key_case($this->getArguments(), CASE_UPPER);
|
||||
|
||||
switch (strtoupper($args[0])) {
|
||||
case 'LIST':
|
||||
return $this->parseClientList($data);
|
||||
case 'KILL':
|
||||
case 'GETNAME':
|
||||
case 'SETNAME':
|
||||
default:
|
||||
return $data;
|
||||
} // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the response to CLIENT LIST and returns a structured list.
|
||||
*
|
||||
* @param string $data Response buffer.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function parseClientList($data)
|
||||
{
|
||||
$clients = [];
|
||||
|
||||
foreach (explode("\n", $data, -1) as $clientData) {
|
||||
$client = [];
|
||||
|
||||
foreach (explode(' ', $clientData) as $kv) {
|
||||
@[$k, $v] = explode('=', $kv);
|
||||
$client[$k] = $v;
|
||||
}
|
||||
|
||||
$clients[] = $client;
|
||||
}
|
||||
|
||||
return $clients;
|
||||
}
|
||||
}
|
||||
26
plugins/cache-redis/Predis/Command/Redis/CLUSTER.php
Normal file
26
plugins/cache-redis/Predis/Command/Redis/CLUSTER.php
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis;
|
||||
|
||||
use Predis\Command\Command as RedisCommand;
|
||||
|
||||
/**
|
||||
* @see https://redis.io/commands/?name=cluster
|
||||
*/
|
||||
class CLUSTER extends RedisCommand
|
||||
{
|
||||
public function getId()
|
||||
{
|
||||
return 'CLUSTER';
|
||||
}
|
||||
}
|
||||
40
plugins/cache-redis/Predis/Command/Redis/COMMAND.php
Normal file
40
plugins/cache-redis/Predis/Command/Redis/COMMAND.php
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis;
|
||||
|
||||
use Predis\Command\Command as BaseCommand;
|
||||
|
||||
/**
|
||||
* @see http://redis.io/commands/command
|
||||
*/
|
||||
class COMMAND extends BaseCommand
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return 'COMMAND';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function parseResponse($data)
|
||||
{
|
||||
// Relay (RESP3) uses maps and it might be good
|
||||
// to make the return value a breaking change
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
54
plugins/cache-redis/Predis/Command/Redis/CONFIG.php
Normal file
54
plugins/cache-redis/Predis/Command/Redis/CONFIG.php
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis;
|
||||
|
||||
use Predis\Command\Command as RedisCommand;
|
||||
|
||||
/**
|
||||
* @see http://redis.io/commands/config-set
|
||||
* @see http://redis.io/commands/config-get
|
||||
* @see http://redis.io/commands/config-resetstat
|
||||
* @see http://redis.io/commands/config-rewrite
|
||||
*/
|
||||
class CONFIG extends RedisCommand
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return 'CONFIG';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function parseResponse($data)
|
||||
{
|
||||
if (is_array($data)) {
|
||||
if ($data !== array_values($data)) {
|
||||
return $data; // Relay
|
||||
}
|
||||
|
||||
$result = [];
|
||||
|
||||
for ($i = 0; $i < count($data); ++$i) {
|
||||
$result[$data[$i]] = $data[++$i];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
47
plugins/cache-redis/Predis/Command/Redis/COPY.php
Normal file
47
plugins/cache-redis/Predis/Command/Redis/COPY.php
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis;
|
||||
|
||||
use Predis\Command\Command as RedisCommand;
|
||||
use Predis\Command\Traits\DB;
|
||||
use Predis\Command\Traits\Replace;
|
||||
|
||||
/**
|
||||
* @see https://redis.io/commands/copy/
|
||||
*
|
||||
* This command copies the value stored at the source key to the destination key.
|
||||
*/
|
||||
class COPY extends RedisCommand
|
||||
{
|
||||
use DB {
|
||||
DB::setArguments as setDB;
|
||||
}
|
||||
use Replace {
|
||||
Replace::setArguments as setReplace;
|
||||
}
|
||||
|
||||
protected static $dbArgumentPositionOffset = 2;
|
||||
|
||||
public function getId()
|
||||
{
|
||||
return 'COPY';
|
||||
}
|
||||
|
||||
public function setArguments(array $arguments)
|
||||
{
|
||||
$this->setDB($arguments);
|
||||
$arguments = $this->getArguments();
|
||||
|
||||
$this->setReplace($arguments);
|
||||
}
|
||||
}
|
||||
28
plugins/cache-redis/Predis/Command/Redis/Container/ACL.php
Normal file
28
plugins/cache-redis/Predis/Command/Redis/Container/ACL.php
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis\Container;
|
||||
|
||||
use Predis\Response\Status;
|
||||
|
||||
/**
|
||||
* @method Status dryRun(string $username, string $command, ...$arguments)
|
||||
* @method array getUser(string $username)
|
||||
* @method Status setUser(string $username, string ...$rules)
|
||||
*/
|
||||
class ACL extends AbstractContainer
|
||||
{
|
||||
public function getContainerCommandId(): string
|
||||
{
|
||||
return 'acl';
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis\Container;
|
||||
|
||||
use Predis\ClientInterface;
|
||||
|
||||
abstract class AbstractContainer implements ContainerInterface
|
||||
{
|
||||
/**
|
||||
* @var ClientInterface
|
||||
*/
|
||||
protected $client;
|
||||
|
||||
public function __construct(ClientInterface $client)
|
||||
{
|
||||
$this->client = $client;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function __call(string $subcommandID, array $arguments)
|
||||
{
|
||||
array_unshift($arguments, strtoupper($subcommandID));
|
||||
|
||||
return $this->client->executeCommand(
|
||||
$this->client->createCommand($this->getContainerCommandId(), $arguments)
|
||||
);
|
||||
}
|
||||
|
||||
abstract public function getContainerCommandId(): string;
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis\Container;
|
||||
|
||||
use Predis\Response\Status;
|
||||
|
||||
/**
|
||||
* @method Status addSlotsRange(int ...$startEndSlots)
|
||||
* @method Status delSlotsRange(int ...$startEndSlots)
|
||||
* @method array links()
|
||||
* @method array shards()
|
||||
*/
|
||||
class CLUSTER extends AbstractContainer
|
||||
{
|
||||
public function getContainerCommandId(): string
|
||||
{
|
||||
return 'CLUSTER';
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis\Container;
|
||||
|
||||
use Predis\ClientConfiguration;
|
||||
use Predis\ClientInterface;
|
||||
use UnexpectedValueException;
|
||||
|
||||
class ContainerFactory
|
||||
{
|
||||
private const CONTAINER_NAMESPACE = "Predis\Command\Redis\Container";
|
||||
|
||||
/**
|
||||
* Mappings for class names that corresponds to PHP reserved words.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $specialMappings = [
|
||||
'FUNCTION' => FunctionContainer::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* Creates container command.
|
||||
*
|
||||
* @param ClientInterface $client
|
||||
* @param string $containerCommandID
|
||||
* @return ContainerInterface
|
||||
*/
|
||||
public static function create(ClientInterface $client, string $containerCommandID): ContainerInterface
|
||||
{
|
||||
$containerCommandID = strtoupper($containerCommandID);
|
||||
$commandModule = self::resolveCommandModuleByPrefix($containerCommandID);
|
||||
|
||||
if (null !== $commandModule) {
|
||||
if (class_exists($containerClass = self::CONTAINER_NAMESPACE . '\\' . $commandModule . '\\' . $containerCommandID)) {
|
||||
return new $containerClass($client);
|
||||
}
|
||||
|
||||
throw new UnexpectedValueException('Given module container command is not supported.');
|
||||
}
|
||||
|
||||
if (class_exists($containerClass = self::CONTAINER_NAMESPACE . '\\' . $containerCommandID)) {
|
||||
return new $containerClass($client);
|
||||
}
|
||||
|
||||
if (array_key_exists($containerCommandID, self::$specialMappings)) {
|
||||
$containerClass = self::$specialMappings[$containerCommandID];
|
||||
|
||||
return new $containerClass($client);
|
||||
}
|
||||
|
||||
throw new UnexpectedValueException('Given container command is not supported.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $commandID
|
||||
* @return string|null
|
||||
*/
|
||||
private static function resolveCommandModuleByPrefix(string $commandID): ?string
|
||||
{
|
||||
$modules = ClientConfiguration::getModules();
|
||||
|
||||
foreach ($modules as $module) {
|
||||
if (preg_match("/^{$module['commandPrefix']}/", $commandID)) {
|
||||
return $module['name'];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis\Container;
|
||||
|
||||
interface ContainerInterface
|
||||
{
|
||||
/**
|
||||
* Creates Redis container command with subcommand as virtual method name
|
||||
* and sends a request to the server.
|
||||
*
|
||||
* @param string $subcommandID
|
||||
* @param array $arguments
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call(string $subcommandID, array $arguments);
|
||||
|
||||
/**
|
||||
* Returns containerCommandId of specific container command.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getContainerCommandId(): string;
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis\Container;
|
||||
|
||||
use Predis\Response\Status;
|
||||
|
||||
/**
|
||||
* @method Status delete(string $libraryName)
|
||||
* @method string dump()
|
||||
* @method Status flush(?string $mode = null)
|
||||
* @method Status kill()
|
||||
* @method array list(string $libraryNamePattern = null, bool $withCode = false)
|
||||
* @method string load(string $functionCode, bool $replace = 'false')
|
||||
* @method Status restore(string $value, string $policy = null)
|
||||
* @method array stats()
|
||||
*/
|
||||
class FunctionContainer extends AbstractContainer
|
||||
{
|
||||
public function getContainerCommandId(): string
|
||||
{
|
||||
return 'FUNCTIONS';
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis\Container\Json;
|
||||
|
||||
use Predis\Command\Redis\Container\AbstractContainer;
|
||||
|
||||
/**
|
||||
* @method array memory(string $key, string $path)
|
||||
* @method array help()
|
||||
*/
|
||||
class JSONDEBUG extends AbstractContainer
|
||||
{
|
||||
public function getContainerCommandId(): string
|
||||
{
|
||||
return 'JSONDEBUG';
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis\Container\Search;
|
||||
|
||||
use Predis\Command\Redis\Container\AbstractContainer;
|
||||
use Predis\Response\Status;
|
||||
|
||||
/**
|
||||
* @method array get(string $option)
|
||||
* @method array help(string $option)
|
||||
* @method Status set(string $option, $value)
|
||||
*/
|
||||
class FTCONFIG extends AbstractContainer
|
||||
{
|
||||
public function getContainerCommandId(): string
|
||||
{
|
||||
return 'FTCONFIG';
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis\Container\Search;
|
||||
|
||||
use Predis\Command\Argument\Search\CursorArguments;
|
||||
use Predis\Command\Redis\Container\AbstractContainer;
|
||||
use Predis\Response\Status;
|
||||
|
||||
/**
|
||||
* @method Status del(string $index, int $cursorId)
|
||||
* @method array read(string $index, int $cursorId, ?CursorArguments $arguments = null)
|
||||
*/
|
||||
class FTCURSOR extends AbstractContainer
|
||||
{
|
||||
public function getContainerCommandId(): string
|
||||
{
|
||||
return 'FTCURSOR';
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis\CountMinSketch;
|
||||
|
||||
use Predis\Command\Command as RedisCommand;
|
||||
|
||||
/**
|
||||
* @see https://redis.io/commands/cms.incrby/
|
||||
*
|
||||
* Increases the count of item by increment.
|
||||
* Multiple items can be increased with one call.
|
||||
*/
|
||||
class CMSINCRBY extends RedisCommand
|
||||
{
|
||||
public function getId()
|
||||
{
|
||||
return 'CMS.INCRBY';
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis\CountMinSketch;
|
||||
|
||||
use Predis\Command\Command as RedisCommand;
|
||||
|
||||
/**
|
||||
* @see https://redis.io/commands/cms.info/
|
||||
*
|
||||
* Returns width, depth and total count of the sketch.
|
||||
*/
|
||||
class CMSINFO extends RedisCommand
|
||||
{
|
||||
public function getId()
|
||||
{
|
||||
return 'CMS.INFO';
|
||||
}
|
||||
|
||||
public function parseResponse($data)
|
||||
{
|
||||
if (count($data) > 1) {
|
||||
$result = [];
|
||||
|
||||
for ($i = 0, $iMax = count($data); $i < $iMax; ++$i) {
|
||||
if (array_key_exists($i + 1, $data)) {
|
||||
$result[(string) $data[$i]] = $data[++$i];
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis\CountMinSketch;
|
||||
|
||||
use Predis\Command\Command as RedisCommand;
|
||||
|
||||
/**
|
||||
* @see https://redis.io/commands/cms.initbydim/
|
||||
*
|
||||
* Initializes a Count-Min Sketch to dimensions specified by user.
|
||||
*/
|
||||
class CMSINITBYDIM extends RedisCommand
|
||||
{
|
||||
public function getId()
|
||||
{
|
||||
return 'CMS.INITBYDIM';
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis\CountMinSketch;
|
||||
|
||||
use Predis\Command\Command as RedisCommand;
|
||||
|
||||
/**
|
||||
* @see https://redis.io/commands/cms.initbyprob/
|
||||
*
|
||||
* Initializes a Count-Min Sketch to accommodate requested tolerances.
|
||||
*/
|
||||
class CMSINITBYPROB extends RedisCommand
|
||||
{
|
||||
public function getId()
|
||||
{
|
||||
return 'CMS.INITBYPROB';
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis\CountMinSketch;
|
||||
|
||||
use Predis\Command\Command as RedisCommand;
|
||||
|
||||
/**
|
||||
* @see https://redis.io/commands/cms.merge/
|
||||
*
|
||||
* Merges several sketches into one sketch.
|
||||
* All sketches must have identical width and depth.
|
||||
* Weights can be used to multiply certain sketches. Default weight is 1.
|
||||
*/
|
||||
class CMSMERGE extends RedisCommand
|
||||
{
|
||||
public function getId()
|
||||
{
|
||||
return 'CMS.MERGE';
|
||||
}
|
||||
|
||||
public function setArguments(array $arguments)
|
||||
{
|
||||
$processedArguments = array_merge([$arguments[0], count($arguments[1])], $arguments[1]);
|
||||
|
||||
if (!empty($arguments[2])) {
|
||||
$processedArguments[] = 'WEIGHTS';
|
||||
$processedArguments = array_merge($processedArguments, $arguments[2]);
|
||||
}
|
||||
|
||||
parent::setArguments($processedArguments);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis\CountMinSketch;
|
||||
|
||||
use Predis\Command\Command as RedisCommand;
|
||||
|
||||
/**
|
||||
* @see https://redis.io/commands/cms.query/
|
||||
*
|
||||
* Returns the count for one or more items in a sketch.
|
||||
*/
|
||||
class CMSQUERY extends RedisCommand
|
||||
{
|
||||
public function getId()
|
||||
{
|
||||
return 'CMS.QUERY';
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis\CuckooFilter;
|
||||
|
||||
use Predis\Command\Command as RedisCommand;
|
||||
|
||||
/**
|
||||
* @see https://redis.io/commands/cf.add/
|
||||
*
|
||||
* Adds an item to the cuckoo filter, creating the filter if it does not exist.
|
||||
*/
|
||||
class CFADD extends RedisCommand
|
||||
{
|
||||
public function getId()
|
||||
{
|
||||
return 'CF.ADD';
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis\CuckooFilter;
|
||||
|
||||
use Predis\Command\Command as RedisCommand;
|
||||
|
||||
/**
|
||||
* @see https://redis.io/commands/cf.addnx/
|
||||
*
|
||||
* Adds an item to a cuckoo filter if the item did not exist previously.
|
||||
*/
|
||||
class CFADDNX extends RedisCommand
|
||||
{
|
||||
public function getId()
|
||||
{
|
||||
return 'CF.ADDNX';
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis\CuckooFilter;
|
||||
|
||||
use Predis\Command\Command as RedisCommand;
|
||||
|
||||
/**
|
||||
* @see https://redis.io/commands/cf.count/
|
||||
*
|
||||
* Returns the number of times an item may be in the filter.
|
||||
* Because this is a probabilistic data structure, this may not necessarily be accurate.
|
||||
*/
|
||||
class CFCOUNT extends RedisCommand
|
||||
{
|
||||
public function getId()
|
||||
{
|
||||
return 'CF.COUNT';
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue