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