Predis to v2.2.2

This commit is contained in:
the-djmaze 2024-04-08 16:29:55 +02:00
parent 9510347d3a
commit 969dca5f7e
449 changed files with 22013 additions and 2 deletions

View 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;
}
}

View 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';
}
}

View 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';
}
}

View 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\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]]]);
}
}

View 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';
}
}

View 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;
}
}

View 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';
}
}

View 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';
}
}

View 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);
}
}

View 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';
}
}

View 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';
}
}

View 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';
}
}

View 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);
}
}

View 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);
}
}

View 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';
}
}

View 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';
}
}

View 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';
}
}

View 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';
}
}

View 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\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';
}
}

View 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\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';
}
}

View file

@ -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;
}
}

View file

@ -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();
}
}

View 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\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';
}
}

View 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\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';
}
}

View 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\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';
}
}

View file

@ -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();
}
}

View 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\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';
}
}

View 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;
}
}

View 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';
}
}

View 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;
}
}

View 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;
}
}

View 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);
}
}

View 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';
}
}

View 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\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;
}

View 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\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';
}
}

View file

@ -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;
}
}

View 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\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;
}

View 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\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';
}
}

View file

@ -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';
}
}

View 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\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';
}
}

View 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\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';
}
}

View 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\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';
}
}

View file

@ -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;
}
}

View 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\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';
}
}

View 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\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';
}
}

View 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\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);
}
}

View 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\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';
}
}

View 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\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';
}
}

View 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\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';
}
}

View 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\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';
}
}

View 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\CuckooFilter;
use Predis\Command\Command as RedisCommand;
/**
* @see https://redis.io/commands/cf.del/
*
* Deletes an item once from the filter.
* If the item exists only once, it will be removed from the filter.
* If the item was added multiple times, it will still be present.
*/
class CFDEL extends RedisCommand
{
public function getId()
{
return 'CF.DEL';
}
}

View 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\CuckooFilter;
use Predis\Command\Command as RedisCommand;
/**
* @see https://redis.io/commands/cf.exists/
*
* Check if an item exists in a Cuckoo Filter key.
*/
class CFEXISTS extends RedisCommand
{
public function getId()
{
return 'CF.EXISTS';
}
}

View file

@ -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\CuckooFilter;
use Predis\Command\Command as RedisCommand;
/**
* @see https://redis.io/commands/cf.info/
*
* Return information about key
*/
class CFINFO extends RedisCommand
{
public function getId()
{
return 'CF.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;
}
}

View file

@ -0,0 +1,52 @@
<?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;
use Predis\Command\Traits\BloomFilters\Capacity;
use Predis\Command\Traits\BloomFilters\Items;
use Predis\Command\Traits\BloomFilters\NoCreate;
class CFINSERT extends RedisCommand
{
use Capacity {
Capacity::setArguments as setCapacity;
}
use NoCreate {
NoCreate::setArguments as setNoCreate;
}
use Items {
Items::setArguments as setItems;
}
protected static $capacityArgumentPositionOffset = 1;
protected static $noCreateArgumentPositionOffset = 2;
protected static $itemsArgumentPositionOffset = 3;
public function getId()
{
return 'CF.INSERT';
}
public function setArguments(array $arguments)
{
$this->setNoCreate($arguments);
$arguments = $this->getArguments();
$this->setItems($arguments);
$arguments = $this->getArguments();
$this->setCapacity($arguments);
$this->filterArguments();
}
}

View file

@ -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\CuckooFilter;
/**
* @see https://redis.io/commands/cf.insertnx/
*
* Adds one or more items to a cuckoo filter, allowing the filter
* to be created with a custom capacity if it does not exist yet.
*/
class CFINSERTNX extends CFINSERT
{
public function getId()
{
return 'CF.INSERTNX';
}
}

View 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\CuckooFilter;
use Predis\Command\Command as RedisCommand;
/**
* @see https://redis.io/commands/cf.loadchunk/
*
* Restores a filter previously saved using SCANDUMP.
* See the SCANDUMP command for example usage.
*/
class CFLOADCHUNK extends RedisCommand
{
public function getId()
{
return 'CF.LOADCHUNK';
}
}

View 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\CuckooFilter;
use Predis\Command\Command as RedisCommand;
/**
* @see https://redis.io/commands/cf.mexists/
*
* Check if one or more items exists in a Cuckoo Filter key.
*/
class CFMEXISTS extends RedisCommand
{
public function getId()
{
return 'CF.MEXISTS';
}
}

View file

@ -0,0 +1,52 @@
<?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;
use Predis\Command\Traits\BloomFilters\BucketSize;
use Predis\Command\Traits\BloomFilters\Expansion;
use Predis\Command\Traits\BloomFilters\MaxIterations;
class CFRESERVE extends RedisCommand
{
use BucketSize {
BucketSize::setArguments as setBucketSize;
}
use MaxIterations {
MaxIterations::setArguments as setMaxIterations;
}
use Expansion {
Expansion::setArguments as setExpansion;
}
protected static $bucketSizeArgumentPositionOffset = 2;
protected static $maxIterationsArgumentPositionOffset = 3;
protected static $expansionArgumentPositionOffset = 4;
public function getId()
{
return 'CF.RESERVE';
}
public function setArguments(array $arguments)
{
$this->setExpansion($arguments);
$arguments = $this->getArguments();
$this->setMaxIterations($arguments);
$arguments = $this->getArguments();
$this->setBucketSize($arguments);
$this->filterArguments();
}
}

View 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\CuckooFilter;
use Predis\Command\Command as RedisCommand;
/**
* @see https://redis.io/commands/cf.scandump/
*
* Begins an incremental save of the cuckoo filter.
* This is useful for large cuckoo filters which cannot fit into the normal DUMP and RESTORE model.
*/
class CFSCANDUMP extends RedisCommand
{
public function getId()
{
return 'CF.SCANDUMP';
}
}

View 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/dbsize
*/
class DBSIZE extends RedisCommand
{
/**
* {@inheritdoc}
*/
public function getId()
{
return 'DBSIZE';
}
}

View 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/decr
*/
class DECR extends RedisCommand
{
/**
* {@inheritdoc}
*/
public function getId()
{
return 'DECR';
}
}

View 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/decrby
*/
class DECRBY extends RedisCommand
{
/**
* {@inheritdoc}
*/
public function getId()
{
return 'DECRBY';
}
}

View file

@ -0,0 +1,39 @@
<?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/del
*/
class DEL extends RedisCommand
{
/**
* {@inheritdoc}
*/
public function getId()
{
return 'DEL';
}
/**
* {@inheritdoc}
*/
public function setArguments(array $arguments)
{
$arguments = self::normalizeArguments($arguments);
parent::setArguments($arguments);
}
}

View 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/discard
*/
class DISCARD extends RedisCommand
{
/**
* {@inheritdoc}
*/
public function getId()
{
return 'DISCARD';
}
}

View 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/dump
*/
class DUMP extends RedisCommand
{
/**
* {@inheritdoc}
*/
public function getId()
{
return 'DUMP';
}
}

View 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/echo
*/
class ECHO_ extends RedisCommand
{
/**
* {@inheritdoc}
*/
public function getId()
{
return 'ECHO';
}
}

View 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;
/**
* @see http://redis.io/commands/evalsha
*/
class EVALSHA extends EVAL_
{
/**
* {@inheritdoc}
*/
public function getId()
{
return 'EVALSHA';
}
/**
* Returns the SHA1 hash of the body of the script.
*
* @return string SHA1 hash.
*/
public function getScriptHash()
{
return $this->getArgument(0);
}
}

View file

@ -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;
/**
* @see https://redis.io/commands/evalsha_ro/
*
* This is a read-only variant of the EVALSHA command
* that cannot execute commands that modify data.
*/
class EVALSHA_RO extends EVAL_RO
{
public function getId()
{
return 'EVALSHA_RO';
}
}

View file

@ -0,0 +1,39 @@
<?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/eval
*/
class EVAL_ extends RedisCommand
{
/**
* {@inheritdoc}
*/
public function getId()
{
return 'EVAL';
}
/**
* Calculates the SHA1 hash of the body of the script.
*
* @return string SHA1 hash.
*/
public function getScriptHash()
{
return sha1($this->getArgument(0));
}
}

View 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\Keys;
/**
* @see https://redis.io/commands/eval_ro/
*
* This is a read-only variant of the EVAL command
* that cannot execute commands that modify data.
*/
class EVAL_RO extends RedisCommand
{
use Keys;
protected static $keysArgumentPositionOffset = 1;
public function getId()
{
return 'EVAL_RO';
}
}

View 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/exec
*/
class EXEC extends RedisCommand
{
/**
* {@inheritdoc}
*/
public function getId()
{
return 'EXEC';
}
}

View 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/exists
*/
class EXISTS extends RedisCommand
{
/**
* {@inheritdoc}
*/
public function getId()
{
return 'EXISTS';
}
}

View file

@ -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\Redis;
use Predis\Command\Command as RedisCommand;
use Predis\Command\Traits\Expire\ExpireOptions;
/**
* @see http://redis.io/commands/expire
*
* Set a timeout on key.
* After the timeout has expired, the key will automatically be deleted.
* A key with an associated timeout is often said to be volatile in Redis terminology.
*/
class EXPIRE extends RedisCommand
{
use ExpireOptions;
/**
* {@inheritdoc}
*/
public function getId()
{
return 'EXPIRE';
}
}

View file

@ -0,0 +1,35 @@
<?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\Expire\ExpireOptions;
/**
* @see http://redis.io/commands/expireat
*
* EXPIREAT has the same effect and semantic as EXPIRE, but instead of specifying
* the number of seconds representing the TTL (time to live), it takes an absolute Unix timestamp
*/
class EXPIREAT extends RedisCommand
{
use ExpireOptions;
/**
* {@inheritdoc}
*/
public function getId()
{
return 'EXPIREAT';
}
}

View 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 https://redis.io/commands/expiretime/
*
* Returns the absolute Unix timestamp (since January 1, 1970)
* in seconds at which the given key will expire.
*/
class EXPIRETIME extends RedisCommand
{
public function getId()
{
return 'EXPIRETIME';
}
}

View file

@ -0,0 +1,48 @@
<?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\Timeout;
use Predis\Command\Traits\To\ServerTo;
class FAILOVER extends RedisCommand
{
use ServerTo {
ServerTo::setArguments as setTo;
}
use Timeout {
Timeout::setArguments as setTimeout;
}
protected static $toArgumentPositionOffset = 0;
protected static $timeoutArgumentPositionOffset = 2;
public function getId()
{
return 'FAILOVER';
}
public function setArguments(array $arguments)
{
if (array_key_exists(1, $arguments) && false !== $arguments[1]) {
$arguments[1] = 'ABORT';
}
$this->setTimeout($arguments);
$arguments = $this->getArguments();
$this->setTo($arguments);
$this->filterArguments();
}
}

View 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\Command as RedisCommand;
use Predis\Command\Traits\Keys;
/**
* @see https://redis.io/commands/fcall/
*
* Invoke a function.
*/
class FCALL extends RedisCommand
{
use Keys;
protected static $keysArgumentPositionOffset = 1;
public function getId()
{
return 'FCALL';
}
}

View file

@ -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\Redis;
use Predis\Command\Command as RedisCommand;
/**
* @see https://redis.io/commands/fcall_ro/
*
* This is a read-only variant of the FCALL command that cannot execute commands that modify data.
*/
class FCALL_RO extends RedisCommand
{
public function getId()
{
return 'FCALL_RO';
}
public function setArguments(array $arguments)
{
$processedArguments = array_merge([$arguments[0], count($arguments[1])], $arguments[1]);
if (count($arguments) > 2) {
for ($i = 2, $iMax = count($arguments); $i < $iMax; $i++) {
$processedArguments[] = $arguments[$i];
}
}
parent::setArguments($processedArguments);
}
}

View 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/flushall
*/
class FLUSHALL extends RedisCommand
{
/**
* {@inheritdoc}
*/
public function getId()
{
return 'FLUSHALL';
}
}

View 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/flushdb
*/
class FLUSHDB extends RedisCommand
{
/**
* {@inheritdoc}
*/
public function getId()
{
return 'FLUSHDB';
}
}

View file

@ -0,0 +1,50 @@
<?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\Strategy\StrategyResolverInterface;
use Predis\Command\Strategy\SubcommandStrategyResolver;
/**
* @see https://redis.io/commands/?name=function
*
* Container command corresponds to any FUNCTION *.
* Represents any FUNCTION command with subcommand as first argument.
*/
class FUNCTIONS extends RedisCommand
{
/**
* @var StrategyResolverInterface
*/
private $strategyResolver;
public function __construct()
{
$this->strategyResolver = new SubcommandStrategyResolver();
}
public function getId()
{
return 'FUNCTION';
}
public function setArguments(array $arguments)
{
$strategy = $this->strategyResolver->resolve('functions', strtolower($arguments[0]));
$arguments = $strategy->processArguments($arguments);
parent::setArguments($arguments);
$this->filterArguments();
}
}

View 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/geoadd
*/
class GEOADD extends RedisCommand
{
/**
* {@inheritdoc}
*/
public function getId()
{
return 'GEOADD';
}
/**
* {@inheritdoc}
*/
public function setArguments(array $arguments)
{
if (count($arguments) === 2 && is_array($arguments[1])) {
foreach (array_pop($arguments) as $item) {
$arguments = array_merge($arguments, $item);
}
}
parent::setArguments($arguments);
}
}

View 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/geodist
*/
class GEODIST extends RedisCommand
{
/**
* {@inheritdoc}
*/
public function getId()
{
return 'GEODIST';
}
}

View 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/geohash
*/
class GEOHASH extends RedisCommand
{
/**
* {@inheritdoc}
*/
public function getId()
{
return 'GEOHASH';
}
/**
* {@inheritdoc}
*/
public function setArguments(array $arguments)
{
if (count($arguments) === 2 && is_array($arguments[1])) {
$members = array_pop($arguments);
$arguments = array_merge($arguments, $members);
}
parent::setArguments($arguments);
}
}

View 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/geopos
*/
class GEOPOS extends RedisCommand
{
/**
* {@inheritdoc}
*/
public function getId()
{
return 'GEOPOS';
}
/**
* {@inheritdoc}
*/
public function setArguments(array $arguments)
{
if (count($arguments) === 2 && is_array($arguments[1])) {
$members = array_pop($arguments);
$arguments = array_merge($arguments, $members);
}
parent::setArguments($arguments);
}
}

View file

@ -0,0 +1,77 @@
<?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;
/**
* @deprecated As of Redis version 6.2.0, this command is regarded as deprecated.
*
* It can be replaced by GEOSEARCH and GEOSEARCHSTORE with the BYRADIUS argument
* when migrating or writing new code.
*
* @see http://redis.io/commands/georadius
*/
class GEORADIUS extends RedisCommand
{
/**
* {@inheritdoc}
*/
public function getId()
{
return 'GEORADIUS';
}
/**
* {@inheritdoc}
*/
public function setArguments(array $arguments)
{
if ($arguments && is_array(end($arguments))) {
$options = array_change_key_case(array_pop($arguments), CASE_UPPER);
if (isset($options['WITHCOORD']) && $options['WITHCOORD'] == true) {
$arguments[] = 'WITHCOORD';
}
if (isset($options['WITHDIST']) && $options['WITHDIST'] == true) {
$arguments[] = 'WITHDIST';
}
if (isset($options['WITHHASH']) && $options['WITHHASH'] == true) {
$arguments[] = 'WITHHASH';
}
if (isset($options['COUNT'])) {
$arguments[] = 'COUNT';
$arguments[] = $options['COUNT'];
}
if (isset($options['SORT'])) {
$arguments[] = strtoupper($options['SORT']);
}
if (isset($options['STORE'])) {
$arguments[] = 'STORE';
$arguments[] = $options['STORE'];
}
if (isset($options['STOREDIST'])) {
$arguments[] = 'STOREDIST';
$arguments[] = $options['STOREDIST'];
}
}
parent::setArguments($arguments);
}
}

View file

@ -0,0 +1,32 @@
<?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;
/**
* @deprecated As of Redis version 6.2.0, this command is regarded as deprecated.
*
* It can be replaced by GEOSEARCH and GEOSEARCHSTORE with the FROMMEMBER arguments
* when migrating or writing new code.
*
* @see http://redis.io/commands/georadiusbymember
*/
class GEORADIUSBYMEMBER extends GEORADIUS
{
/**
* {@inheritdoc}
*/
public function getId()
{
return 'GEORADIUSBYMEMBER';
}
}

View file

@ -0,0 +1,122 @@
<?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\By\GeoBy;
use Predis\Command\Traits\Count;
use Predis\Command\Traits\From\GeoFrom;
use Predis\Command\Traits\Sorting;
use Predis\Command\Traits\With\WithCoord;
use Predis\Command\Traits\With\WithDist;
use Predis\Command\Traits\With\WithHash;
/**
* @see https://redis.io/commands/geosearch/
*
* Return the members of a sorted set populated with geospatial information using GEOADD,
* which are within the borders of the area specified by a given shape.
*
* This command extends the GEORADIUS command, so in addition to searching
* within circular areas, it supports searching within rectangular areas.
*/
class GEOSEARCH extends RedisCommand
{
use GeoFrom {
GeoFrom::setArguments as setFrom;
}
use GeoBy {
GeoBy::setArguments as setBy;
}
use Sorting {
Sorting::setArguments as setSorting;
}
use Count {
Count::setArguments as setCount;
}
use WithCoord {
WithCoord::setArguments as setWithCoord;
}
use WithDist {
WithDist::setArguments as setWithDist;
}
use WithHash {
WithHash::setArguments as setWithHash;
}
protected static $sortArgumentPositionOffset = 3;
protected static $countArgumentPositionOffset = 4;
protected static $withCoordArgumentPositionOffset = 6;
protected static $withDistArgumentPositionOffset = 7;
protected static $withHashArgumentPositionOffset = 8;
public function getId()
{
return 'GEOSEARCH';
}
public function setArguments(array $arguments)
{
$this->setSorting($arguments);
$arguments = $this->getArguments();
$this->setWithCoord($arguments);
$arguments = $this->getArguments();
$this->setWithDist($arguments);
$arguments = $this->getArguments();
$this->setWithHash($arguments);
$arguments = $this->getArguments();
$this->setCount($arguments, $arguments[5] ?? false);
$arguments = $this->getArguments();
$this->setFrom($arguments);
$arguments = $this->getArguments();
$this->setBy($arguments);
$this->filterArguments();
}
public function parseResponse($data)
{
$parsedData = [];
$itemKey = '';
foreach ($data as $item) {
if (!is_array($item)) {
$parsedData[] = $item;
continue;
}
foreach ($item as $key => $itemRow) {
if ($key === 0) {
$itemKey = $itemRow;
continue;
}
if (is_string($itemRow)) {
$parsedData[$itemKey]['dist'] = round((float) $itemRow, 5);
} elseif (is_int($itemRow)) {
$parsedData[$itemKey]['hash'] = $itemRow;
} else {
$parsedData[$itemKey]['lng'] = round($itemRow[0], 5);
$parsedData[$itemKey]['lat'] = round($itemRow[1], 5);
}
}
}
return $parsedData;
}
}

View file

@ -0,0 +1,71 @@
<?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\By\GeoBy;
use Predis\Command\Traits\Count;
use Predis\Command\Traits\From\GeoFrom;
use Predis\Command\Traits\Sorting;
use Predis\Command\Traits\Storedist;
/**
* @see https://redis.io/commands/geosearchstore/
*
* This command is like GEOSEARCH, but stores the result in destination key.
*/
class GEOSEARCHSTORE extends RedisCommand
{
use GeoFrom {
GeoFrom::setArguments as setFrom;
}
use GeoBy {
GeoBy::setArguments as setBy;
}
use Sorting {
Sorting::setArguments as setSorting;
}
use Count {
Count::setArguments as setCount;
}
use Storedist {
Storedist::setArguments as setStoreDist;
}
protected static $sortArgumentPositionOffset = 4;
protected static $countArgumentPositionOffset = 5;
protected static $storeDistArgumentPositionOffset = 7;
public function getId()
{
return 'GEOSEARCHSTORE';
}
public function setArguments(array $arguments)
{
$this->setStoreDist($arguments);
$arguments = $this->getArguments();
$this->setCount($arguments, $arguments[6] ?? false);
$arguments = $this->getArguments();
$this->setSorting($arguments);
$arguments = $this->getArguments();
$this->setFrom($arguments);
$arguments = $this->getArguments();
$this->setBy($arguments);
$this->filterArguments();
}
}

View 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/get
*/
class GET extends RedisCommand
{
/**
* {@inheritdoc}
*/
public function getId()
{
return 'GET';
}
}

View 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/getbit
*/
class GETBIT extends RedisCommand
{
/**
* {@inheritdoc}
*/
public function getId()
{
return 'GETBIT';
}
}

View file

@ -0,0 +1,23 @@
<?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;
class GETDEL extends RedisCommand
{
public function getId()
{
return 'GETDEL';
}
}

View file

@ -0,0 +1,63 @@
<?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 UnexpectedValueException;
class GETEX extends RedisCommand
{
/**
* @var string[]
*/
private static $modifierEnum = [
'ex' => 'EX',
'px' => 'PX',
'exat' => 'EXAT',
'pxat' => 'PXAT',
'persist' => 'PERSIST',
];
public function getId()
{
return 'GETEX';
}
public function setArguments(array $arguments)
{
if (!array_key_exists(1, $arguments) || $arguments[1] === '') {
parent::setArguments([$arguments[0]]);
return;
}
if (!in_array(strtoupper($arguments[1]), self::$modifierEnum)) {
$enumValues = implode(', ', array_keys(self::$modifierEnum));
throw new UnexpectedValueException("Modifier argument accepts only: {$enumValues} values");
}
if ($arguments[1] === 'persist') {
parent::setArguments([$arguments[0], self::$modifierEnum[$arguments[1]]]);
return;
}
$arguments[1] = self::$modifierEnum[$arguments[1]];
if (!array_key_exists(2, $arguments)) {
throw new UnexpectedValueException('You should provide value for current modifier');
}
parent::setArguments($arguments);
}
}

View 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/getrange
*/
class GETRANGE extends RedisCommand
{
/**
* {@inheritdoc}
*/
public function getId()
{
return 'GETRANGE';
}
}

View 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/getset
*/
class GETSET extends RedisCommand
{
/**
* {@inheritdoc}
*/
public function getId()
{
return 'GETSET';
}
}

View file

@ -0,0 +1,39 @@
<?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/hdel
*/
class HDEL extends RedisCommand
{
/**
* {@inheritdoc}
*/
public function getId()
{
return 'HDEL';
}
/**
* {@inheritdoc}
*/
public function setArguments(array $arguments)
{
$arguments = self::normalizeVariadic($arguments);
parent::setArguments($arguments);
}
}

View 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/hexists
*/
class HEXISTS extends RedisCommand
{
/**
* {@inheritdoc}
*/
public function getId()
{
return 'HEXISTS';
}
}

View 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/hget
*/
class HGET extends RedisCommand
{
/**
* {@inheritdoc}
*/
public function getId()
{
return 'HGET';
}
}

View 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;
/**
* @see http://redis.io/commands/hgetall
*/
class HGETALL extends RedisCommand
{
/**
* {@inheritdoc}
*/
public function getId()
{
return 'HGETALL';
}
/**
* {@inheritdoc}
*/
public function parseResponse($data)
{
if ($data !== array_values($data)) {
return $data; // Relay
}
$result = [];
for ($i = 0; $i < count($data); ++$i) {
$result[$data[$i]] = $data[++$i];
}
return $result;
}
}

View 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/hincrby
*/
class HINCRBY extends RedisCommand
{
/**
* {@inheritdoc}
*/
public function getId()
{
return 'HINCRBY';
}
}

Some files were not shown because too many files have changed in this diff Show more