mirror of
https://github.com/predis/predis.git
synced 2026-08-23 21:29:38 +00:00
Resolve merge conflicts
This commit is contained in:
@@ -70,6 +70,7 @@ use Predis\Command\Container\Search\FTCURSOR;
|
||||
* @method $this ttl($key)
|
||||
* @method $this type($key)
|
||||
* @method $this append($key, $value)
|
||||
* @method $this bitcount($key, $start = null, $end = null, string $index = 'byte')
|
||||
* @method $this bfadd(string $key, $item)
|
||||
* @method $this bfexists(string $key, $item)
|
||||
* @method $this bfinfo(string $key, string $modifier = '')
|
||||
@@ -79,7 +80,6 @@ use Predis\Command\Container\Search\FTCURSOR;
|
||||
* @method $this bfmexists(string $key, ...$item)
|
||||
* @method $this bfreserve(string $key, float $errorRate, int $capacity, int $expansion = -1, bool $nonScaling = false)
|
||||
* @method $this bfscandump(string $key, int $iterator)
|
||||
* @method $this bitcount(string $key, $start = null, $end = null, string $index = 'byte')
|
||||
* @method $this bitop($operation, $destkey, $key)
|
||||
* @method $this bitfield($key, $subcommand, ...$subcommandArg)
|
||||
* @method $this bitpos($key, $bit, $start = null, $end = null, string $index = 'byte')
|
||||
@@ -108,6 +108,7 @@ use Predis\Command\Container\Search\FTCURSOR;
|
||||
* @method $this decr($key)
|
||||
* @method $this decrby($key, $decrement)
|
||||
* @method $this failover(?To $to = null, bool $abort = false, int $timeout = -1)
|
||||
* @method $this get($key)
|
||||
* @method $this fcall(string $function, array $keys, ...$args)
|
||||
* @method $this fcall_ro(string $function, array $keys, ...$args)
|
||||
* @method $this ftaggregate(string $index, string $query, ?AggregateArguments $arguments = null)
|
||||
@@ -132,7 +133,6 @@ use Predis\Command\Container\Search\FTCURSOR;
|
||||
* @method $this ftsyndump(string $index)
|
||||
* @method $this ftsynupdate(string $index, string $synonymGroupId, ?SynUpdateArguments $arguments = null, string ...$terms)
|
||||
* @method $this fttagvals(string $index, string $fieldName)
|
||||
* @method $this get($key)
|
||||
* @method $this getbit($key, $offset)
|
||||
* @method $this getex(string $key, $modifier = '', $value = false)
|
||||
* @method $this getrange($key, $start, $end)
|
||||
|
||||
@@ -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($subcommandID, $arguments)
|
||||
{
|
||||
array_unshift($arguments, strtoupper($subcommandID));
|
||||
|
||||
return $this->client->executeCommand(
|
||||
$this->client->createCommand($this->getContainerCommandId(), $arguments)
|
||||
);
|
||||
}
|
||||
|
||||
abstract public function getContainerCommandId(): string;
|
||||
}
|
||||
@@ -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\Container;
|
||||
|
||||
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);
|
||||
|
||||
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 command is not supported.');
|
||||
}
|
||||
}
|
||||
@@ -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 $subcommandID
|
||||
* @param $arguments
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call($subcommandID, $arguments);
|
||||
|
||||
/**
|
||||
* Returns containerCommandId of specific container command.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getContainerCommandId(): string;
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
use Predis\Response\Status;
|
||||
|
||||
/**
|
||||
* @method string load(string $functionCode, bool $replace = 'false')
|
||||
* @method Status delete(string $libraryName)
|
||||
*/
|
||||
class FunctionContainer extends AbstractContainer
|
||||
{
|
||||
public function getContainerCommandId(): string
|
||||
{
|
||||
return 'functions';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?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 PHPUnit\Framework\TestCase;
|
||||
use Predis\ClientInterface;
|
||||
use Predis\Command\CommandInterface;
|
||||
|
||||
class AbstractContainerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var AbstractContainer
|
||||
*/
|
||||
private $testClass;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $arguments;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $expectedValue;
|
||||
|
||||
/**
|
||||
* @var \PHPUnit\Framework\MockObject\MockObject|ClientInterface
|
||||
*/
|
||||
private $mockClient;
|
||||
|
||||
/**
|
||||
* @var \PHPUnit\Framework\MockObject\MockObject|CommandInterface
|
||||
*/
|
||||
private $mockCommand;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->arguments = ['arg1', 'arg2'];
|
||||
$this->expectedValue = ['value'];
|
||||
$this->mockCommand = $this->getMockBuilder(CommandInterface::class)->getMock();
|
||||
$this->mockClient = $this->getMockBuilder(ClientInterface::class)->getMock();
|
||||
|
||||
$this->testClass = new class($this->mockClient) extends AbstractContainer {
|
||||
public function getContainerCommandId(): string
|
||||
{
|
||||
return 'test';
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testGetContainerId(): void
|
||||
{
|
||||
$this->assertSame('test', $this->testClass->getContainerCommandId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testCallReturnsValidCommandResponse(): void
|
||||
{
|
||||
$modifiedArguments = ['TEST', ['arg1', 'arg2']];
|
||||
|
||||
$this->mockClient
|
||||
->expects($this->once())
|
||||
->method('createCommand')
|
||||
->with($this->equalTo('test'), $modifiedArguments)
|
||||
->willReturn($this->mockCommand);
|
||||
|
||||
$this->mockClient
|
||||
->expects($this->once())
|
||||
->method('executeCommand')
|
||||
->with($this->mockCommand)
|
||||
->willReturn($this->expectedValue);
|
||||
|
||||
$this->assertSame($this->expectedValue, $this->testClass->test($this->arguments));
|
||||
}
|
||||
}
|
||||
@@ -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\Command\Redis\Container;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Predis\ClientInterface;
|
||||
use UnexpectedValueException;
|
||||
|
||||
class ContainerFactoryTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var \PHPUnit\Framework\MockObject\MockObject|ClientInterface
|
||||
*/
|
||||
private $mockClient;
|
||||
|
||||
/**
|
||||
* @var ContainerFactory
|
||||
*/
|
||||
private $factory;
|
||||
|
||||
/**
|
||||
* @var ContainerInterface
|
||||
*/
|
||||
private $expectedContainer;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->mockClient = $this->getMockBuilder(ClientInterface::class)->getMock();
|
||||
$this->expectedContainer = new FunctionContainer($this->mockClient);
|
||||
$this->factory = new ContainerFactory();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testCreatesReturnsExistingCommandContainerClass(): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$this->expectedContainer,
|
||||
$this->factory::create($this->mockClient, 'function')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testThrowsExceptionOnNonExistingCommand(): void
|
||||
{
|
||||
$this->expectException(UnexpectedValueException::class);
|
||||
$this->expectExceptionMessage('Given command is not supported.');
|
||||
|
||||
$this->factory::create($this->mockClient, 'foobar');
|
||||
}
|
||||
}
|
||||
@@ -886,7 +886,8 @@ class MultiExecTest extends PredisTestCase
|
||||
?array $expected = [],
|
||||
?array &$commands = [],
|
||||
?array &$cas = []
|
||||
): callable {
|
||||
): callable
|
||||
{
|
||||
$multi = $watch = $abort = false;
|
||||
|
||||
return function (CommandInterface $command) use (&$expected, &$commands, &$cas, &$multi, &$watch, &$abort) {
|
||||
|
||||
Reference in New Issue
Block a user