Remove deprecated Triggers & Functions support (#1524)

* Removed deprecated Triggers & Functions support

* Codestyle fixes
This commit is contained in:
Vladyslav Vildanov
2025-03-28 16:10:01 +02:00
committed by GitHub
parent 73e6a03fd8
commit 52e9f6d106
13 changed files with 0 additions and 762 deletions
-4
View File
@@ -44,7 +44,6 @@ use Predis\Command\Container\FUNCTIONS;
use Predis\Command\Container\Json\JSONDEBUG;
use Predis\Command\Container\Search\FTCONFIG;
use Predis\Command\Container\Search\FTCURSOR;
use Predis\Command\Container\TFUNCTION;
use Predis\Command\Container\XGROUP;
/**
@@ -247,8 +246,6 @@ use Predis\Command\Container\XGROUP;
* @method $this tdigestreset(string $key)
* @method $this tdigestrevrank(string $key, float ...$value)
* @method $this tdigesttrimmed_mean(string $key, float $lowCutQuantile, float $highCutQuantile)
* @method $this tfcall(string $libraryName, string $functionName, array $keys = [], array $arguments = [])
* @method $this tfcallasync(string $libraryName, string $functionName, array $keys = [], array $arguments = [])
* @method $this topkadd(string $key, ...$items)
* @method $this topkincrby(string $key, ...$itemIncrement)
* @method $this topkinfo(string $key)
@@ -354,7 +351,6 @@ use Predis\Command\Container\XGROUP;
* @property JSONDEBUG $jsondebug
* @property ACL $acl
* @property XGROUP $xgroup
* @property TFUNCTION $tfunction
*/
interface ClientContextInterface
{
-4
View File
@@ -44,7 +44,6 @@ use Predis\Command\Container\FUNCTIONS;
use Predis\Command\Container\Json\JSONDEBUG;
use Predis\Command\Container\Search\FTCONFIG;
use Predis\Command\Container\Search\FTCURSOR;
use Predis\Command\Container\TFUNCTION;
use Predis\Command\Container\XGROUP;
use Predis\Command\Container\XINFO;
use Predis\Command\FactoryInterface;
@@ -258,8 +257,6 @@ use Predis\Response\Status;
* @method Status tdigestreset(string $key)
* @method array tdigestrevrank(string $key, float ...$value)
* @method string tdigesttrimmed_mean(string $key, float $lowCutQuantile, float $highCutQuantile)
* @method mixed tfcall(string $libraryName, string $functionName, array $keys = [], array $arguments = [])
* @method mixed tfcallasync(string $libraryName, string $functionName, array $keys = [], array $arguments = [])
* @method array topkadd(string $key, ...$items)
* @method array topkincrby(string $key, ...$itemIncrement)
* @method array topkinfo(string $key)
@@ -377,7 +374,6 @@ use Predis\Response\Status;
* @property ACL $acl
* @property XGROUP $xgroup
* @property XINFO $xinfo
* @property TFUNCTION $tfunction
*/
interface ClientInterface
{
-5
View File
@@ -179,11 +179,6 @@ abstract class ClusterStrategy implements StrategyInterface
'SSUBSCRIBE' => $getKeyFromAllArguments,
'SUNSUBSCRIBE' => [$this, 'getKeyFromSUnsubscribeCommand'],
'SPUBLISH' => $getKeyFromFirstArgument,
/* gears */
'TFUNCTION' => [$this, 'getFakeKey'],
'TFCALL' => [$this, 'getFakeKey'],
'TFCALLASYNC' => [$this, 'getFakeKey'],
];
}
-28
View File
@@ -1,28 +0,0 @@
<?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\Container;
use Predis\Response\Status;
/**
* @method Status load(string $libraryCode, bool $replace = false, string $config = null)
* @method Status delete(string $libraryName)
* @method array list(bool $withCode = false, int $verboseLevel = 0, string $libraryName = null)
*/
class TFUNCTION extends AbstractContainer
{
public function getContainerCommandId(): string
{
return 'TFUNCTION';
}
}
-49
View File
@@ -1,49 +0,0 @@
<?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;
/**
* Invokes given function from loaded Redis Gears library.
*
* In order to be used in cluster mode
* @see https://github.com/predis/predis#redis-gears-with-cluster
*/
class TFCALL extends RedisCommand
{
public function getId()
{
return 'TFCALL';
}
/**
* @param array $arguments
* @return void
*/
public function setArguments(array $arguments)
{
$keysCount = (array_key_exists(2, $arguments)) ? count($arguments[2]) : 0;
$processedArguments = [$arguments[0] . '.' . $arguments[1], $keysCount];
if (array_key_exists(2, $arguments)) {
$processedArguments = array_merge($processedArguments, $arguments[2]);
}
if (array_key_exists(3, $arguments) && !empty($arguments[3])) {
$processedArguments = array_merge($processedArguments, $arguments[3]);
}
parent::setArguments($processedArguments);
}
}
-28
View File
@@ -1,28 +0,0 @@
<?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;
/**
* Same as TFCALL command but executes in async mode.
* @see TFCALL
*
* In order to be used in cluster mode
* @see https://github.com/predis/predis#redis-gears-with-cluster
*/
class TFCALLASYNC extends TFCALL
{
public function getId()
{
return 'TFCALLASYNC';
}
}
-131
View File
@@ -1,131 +0,0 @@
<?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;
/**
* Load a new library to RedisGears.
*
* In order to be used in cluster mode
* @see https://github.com/predis/predis#redis-gears-with-cluster
*/
class TFUNCTION extends RedisCommand
{
/**
* @var string
*/
private $subcommand;
public function getId()
{
return 'TFUNCTION';
}
public function setArguments(array $arguments)
{
$this->subcommand = $arguments[0];
switch ($this->subcommand) {
case 'LOAD':
$this->setLoadArguments($arguments);
break;
case 'LIST':
$this->setListArguments($arguments);
break;
default:
parent::setArguments($arguments);
}
}
/**
* @param array $arguments
* @return void
*/
private function setLoadArguments(array $arguments): void
{
$subcommand = array_shift($arguments);
$processedArguments = [$subcommand];
$argumentsCount = min(count($arguments), 3);
if ($argumentsCount > 1 && true === $arguments[1]) {
$processedArguments[] = 'REPLACE';
}
if ($argumentsCount > 2 && null !== $arguments[2]) {
array_push($processedArguments, 'CONFIG', $arguments[2]);
}
$processedArguments[] = $arguments[0];
parent::setArguments($processedArguments);
}
/**
* @param array $arguments
* @return void
*/
private function setListArguments(array $arguments): void
{
$subcommand = array_shift($arguments);
$processedArguments = [$subcommand];
if (array_key_exists(0, $arguments) && true === $arguments[0]) {
$processedArguments[] = 'WITHCODE';
}
if (array_key_exists(1, $arguments) && $arguments[1] > 0) {
$verboseLevel = min($arguments[1], 3);
for ($i = 0; $i < $verboseLevel; $i++) {
$processedArguments[] = 'v';
}
}
if (array_key_exists(2, $arguments) && null !== $arguments[2]) {
array_push($processedArguments, 'LIBRARY', $arguments[2]);
}
parent::setArguments($processedArguments);
}
/**
* @param $data
* @return array|string|null
*/
public function parseResponse($data)
{
if ($this->subcommand === 'LIST') {
$result = [];
for ($i = 0, $iMax = count($data); $i < $iMax; $i++) {
if (is_array($data[$i])) {
$result[$i] = $this->parseResponse($data[$i]);
}
if (array_key_exists($i + 1, $data)) {
if (is_array($data[$i + 1])) {
$result[$data[$i]] = $this->parseResponse($data[++$i]);
} else {
$result[$data[$i]] = $data[++$i];
}
}
}
return $result;
}
return $data;
}
}
@@ -483,11 +483,6 @@ class PredisStrategyTest extends PredisTestCase
'SSUBSCRIBE' => 'keys-all',
'SUNSUBSCRIBE' => 'keys-sunsubscribe',
'SPUBLISH' => 'keys-first',
/* gears */
'TFUNCTION' => 'keys-fake',
'TFCALL' => 'keys-fake',
'TFCALLASYNC' => 'keys-fake',
];
if (isset($type)) {
@@ -506,11 +506,6 @@ class RedisStrategyTest extends PredisTestCase
'SSUBSCRIBE' => 'keys-all',
'SUNSUBSCRIBE' => 'keys-sunsubscribe',
'SPUBLISH' => 'keys-first',
/* gears */
'TFUNCTION' => 'keys-fake',
'TFCALL' => 'keys-fake',
'TFCALLASYNC' => 'keys-fake',
];
if (isset($type)) {
@@ -1,27 +0,0 @@
<?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\Container;
use Predis\ClientInterface;
use PredisTestCase;
class TFUNCTION_Test extends PredisTestCase
{
public function testGetId(): void
{
$mockClient = $this->getMockBuilder(ClientInterface::class)->getMock();
$container = new TFUNCTION($mockClient);
$this->assertSame('TFUNCTION', $container->getContainerCommandId());
}
}
@@ -1,127 +0,0 @@
<?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\RawCommand;
use Predis\Connection\Cluster\ClusterInterface;
use Predis\Response\ServerException;
class TFCALLASYNC_Test extends PredisCommandTestCase
{
/**
* {@inheritDoc}
*/
protected function getExpectedCommand(): string
{
return TFCALLASYNC::class;
}
/**
* {@inheritDoc}
*/
protected function getExpectedId(): string
{
return 'TFCALLASYNC';
}
/**
* @dataProvider argumentsProvider
* @group disconnected
* @param array $actualArguments
* @param array $expectedResponse
* @return void
*/
public function testFilterArguments(array $actualArguments, array $expectedResponse): void
{
$command = $this->getCommand();
$command->setArguments($actualArguments);
$this->assertSame($expectedResponse, $command->getArguments());
}
/**
* @group connected
* @group gears
* @requiresRedisGearsVersion >= 2.0.0
* @return void
*/
public function testCallLoadedFunctionFromRedisGearsLibrary(): void
{
$redis = $this->getClient();
$libCode = "#!js api_version=1.0 name=lib\n redis.registerFunction('foo', ()=>{return 'bar'})";
$this->assertEquals('OK', $redis->tfunction->load($libCode));
$this->assertEquals('bar', $redis->tfcallasync('lib', 'foo'));
$this->assertEquals('OK', $redis->tfunction->delete('lib'));
}
/**
* @group connected
* @group cluster
* @group gears-cluster
* @requiresRedisGearsVersion >= 2.0.0
* @return void
*/
public function testCallLoadedFunctionFromRedisGearsLibraryClusterMode(): void
{
$redis = $this->getClient();
/** @var ClusterInterface $connection */
$connection = $redis->getConnection();
// https://github.com/predis/predis#redis-gears-with-cluster
$connection->executeCommandOnEachNode(
new RawCommand('REDISGEARS_2.REFRESHCLUSTER')
);
$libCode = "#!js api_version=1.0 name=lib\n redis.registerFunction('foo', ()=>{return 'bar'})";
$this->assertEquals('OK', $redis->tfunction->load($libCode));
$this->assertEquals('bar', $redis->tfcallasync('lib', 'foo'));
$this->assertEquals('OK', $redis->tfunction->delete('lib'));
}
/**
* @group connected
* @group gears
* @requiresRedisGearsVersion >= 2.0.0
* @return void
*/
public function testThrowsExceptionOnNonExistingLibrary(): void
{
$redis = $this->getClient();
$this->expectException(ServerException::class);
$this->expectExceptionMessage('Unknown library lib');
$redis->tfcallasync('lib', 'foo');
}
public function argumentsProvider(): array
{
return [
'with default arguments' => [
['lib', 'function'],
['lib.function', 0],
],
'with keys' => [
['lib', 'function', ['key1', 'key2']],
['lib.function', 2, 'key1', 'key2'],
],
'with keys and arguments' => [
['lib', 'function', ['key1', 'key2'], ['arg1', 'arg2']],
['lib.function', 2, 'key1', 'key2', 'arg1', 'arg2'],
],
];
}
}
-128
View File
@@ -1,128 +0,0 @@
<?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\RawCommand;
use Predis\Connection\Cluster\ClusterInterface;
use Predis\Response\ServerException;
class TFCALL_Test extends PredisCommandTestCase
{
/**
* {@inheritDoc}
*/
protected function getExpectedCommand(): string
{
return TFCALL::class;
}
/**
* {@inheritDoc}
*/
protected function getExpectedId(): string
{
return 'TFCALL';
}
/**
* @dataProvider argumentsProvider
* @group disconnected
* @param array $actualArguments
* @param array $expectedResponse
* @return void
*/
public function testFilterArguments(array $actualArguments, array $expectedResponse): void
{
$command = $this->getCommand();
$command->setArguments($actualArguments);
$this->assertSame($expectedResponse, $command->getArguments());
}
/**
* @group connected
* @group gears
* @requiresRedisGearsVersion >= 2.0.0
* @return void
*/
public function testCallLoadedFunctionFromRedisGearsLibrary(): void
{
$redis = $this->getClient();
$libCode = "#!js api_version=1.0 name=lib\n redis.registerFunction('foo', ()=>{return 'bar'})";
$this->assertEquals('OK', $redis->tfunction->load($libCode));
$this->assertEquals('bar', $redis->tfcall('lib', 'foo'));
$this->assertEquals('OK', $redis->tfunction->delete('lib'));
}
/**
* @group connected
* @group cluster
* @group gears-cluster
* @requiresRedisGearsVersion >= 2.0.0
* @requiresRedisVersion >= 7.1.0
* @return void
*/
public function testCallLoadedFunctionFromRedisGearsLibraryClusterMode(): void
{
$redis = $this->getClient();
/** @var ClusterInterface $connection */
$connection = $redis->getConnection();
// https://github.com/predis/predis#redis-gears-with-cluster
$connection->executeCommandOnEachNode(
new RawCommand('REDISGEARS_2.REFRESHCLUSTER')
);
$libCode = "#!js api_version=1.0 name=lib\n redis.registerFunction('foo', ()=>{return 'bar'})";
$this->assertEquals('OK', $redis->tfunction->load($libCode));
$this->assertEquals('bar', $redis->tfcall('lib', 'foo'));
$this->assertEquals('OK', $redis->tfunction->delete('lib'));
}
/**
* @group connected
* @group gears
* @requiresRedisGearsVersion >= 2.0.0
* @return void
*/
public function testThrowsExceptionOnNonExistingLibrary(): void
{
$redis = $this->getClient();
$this->expectException(ServerException::class);
$this->expectExceptionMessage('Unknown library lib');
$redis->tfcall('lib', 'foo');
}
public function argumentsProvider(): array
{
return [
'with default arguments' => [
['lib', 'function'],
['lib.function', 0],
],
'with keys' => [
['lib', 'function', ['key1', 'key2']],
['lib.function', 2, 'key1', 'key2'],
],
'with keys and arguments' => [
['lib', 'function', ['key1', 'key2'], ['arg1', 'arg2']],
['lib.function', 2, 'key1', 'key2', 'arg1', 'arg2'],
],
];
}
}
@@ -1,221 +0,0 @@
<?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\RawCommand;
use Predis\Connection\Cluster\ClusterInterface;
class TFUNCTION_Test extends PredisCommandTestCase
{
/**
* {@inheritDoc}
*/
protected function getExpectedCommand(): string
{
return TFUNCTION::class;
}
/**
* {@inheritDoc}
*/
protected function getExpectedId(): string
{
return 'TFUNCTION';
}
/**
* @dataProvider loadArgumentsProvider
* @group disconnected
* @param array $actualArguments
* @param array $expectedResponse
* @return void
*/
public function testSetLoadArguments(array $actualArguments, array $expectedResponse): void
{
$command = $this->getCommand();
$command->setArguments($actualArguments);
$this->assertSame($expectedResponse, $command->getArguments());
}
/**
* @dataProvider listArgumentsProvider
* @group disconnected
* @param array $actualArguments
* @param array $expectedResponse
* @return void
*/
public function testSetListArguments(array $actualArguments, array $expectedResponse): void
{
$command = $this->getCommand();
$command->setArguments($actualArguments);
$this->assertSame($expectedResponse, $command->getArguments());
}
/**
* @group disconnected
* @return void
*/
public function testDeleteFilterArguments(): void
{
$arguments = ['DELETE', 'libname'];
$expected = ['DELETE', 'libname'];
$command = $this->getCommand();
$command->setArguments($arguments);
$this->assertSameValues($expected, $command->getArguments());
}
/**
* @group disconnected
* @dataProvider responseProvider
* @param array $arguments
* @param array $actualData
* @param array $expectedData
* @return void
*/
public function testParseResponse(array $arguments, array $actualData, array $expectedData): void
{
$command = $this->getCommand();
$command->setArguments($arguments);
$this->assertEquals($expectedData, $command->parseResponse($actualData));
}
/**
* @group connected
* @group gears
* @requiresRedisGearsVersion >= 2.0.0
* @return void
*/
public function testLoadAndDeletesGivenLibraryFromRedisGears(): void
{
$redis = $this->getClient();
$libCode = "#!js api_version=1.0 name=lib\n redis.registerFunction('foo', ()=>{return 'bar'})";
$this->assertEquals('OK', $redis->tfunction->load($libCode));
$this->assertEquals('OK', $redis->tfunction->delete('lib'));
}
/**
* @group connected
* @group cluster
* @group gears-cluster
* @requiresRedisGearsVersion >= 2.0.0
* @requiresRedisVersion >= 7.1.0
* @return void
*/
public function testLoadAndDeletesGivenLibraryFromRedisGearsClusterMode(): void
{
$redis = $this->getClient();
/** @var ClusterInterface $connection */
$connection = $redis->getConnection();
// https://github.com/predis/predis#redis-gears-with-cluster
$connection->executeCommandOnEachNode(
new RawCommand('REDISGEARS_2.REFRESHCLUSTER')
);
$libCode = "#!js api_version=1.0 name=lib\n redis.registerFunction('foo', ()=>{return 'bar'})";
$this->assertEquals('OK', $redis->tfunction->load($libCode));
$this->assertEquals('OK', $redis->tfunction->delete('lib'));
}
/**
* @group connected
* @group gears
* @requiresRedisGearsVersion >= 2.0.0
* @return void
*/
public function testListsRedisGearsLibraries(): void
{
$redis = $this->getClient();
$libCode = "#!js api_version=1.0 name=lib\n redis.registerFunction('foo', ()=>{return 'bar'})";
$this->assertEquals('OK', $redis->tfunction->load($libCode));
$this->assertEquals('lib', $redis->tfunction->list()[0]['name']);
$this->assertEquals('OK', $redis->tfunction->delete('lib'));
}
public function loadArgumentsProvider(): array
{
return [
'with default arguments' => [
['LOAD', 'libcode'],
['LOAD', 'libcode'],
],
'with REPLACE argument' => [
['LOAD', 'libcode', true],
['LOAD', 'REPLACE', 'libcode'],
],
'with CONFIG argument' => [
['LOAD', 'libcode', false, 'config'],
['LOAD', 'CONFIG', 'config', 'libcode'],
],
'with all arguments' => [
['LOAD', 'libcode', true, 'config'],
['LOAD', 'REPLACE', 'CONFIG', 'config', 'libcode'],
],
];
}
public function listArgumentsProvider(): array
{
return [
'with default arguments' => [
['LIST'],
['LIST'],
],
'with WITHCODE argument' => [
['LIST', true],
['LIST', 'WITHCODE'],
],
'with verbose level argument' => [
['LIST', false, 2],
['LIST', 'v', 'v'],
],
'with verbose level above threshold' => [
['LIST', false, 9999],
['LIST', 'v', 'v', 'v'],
],
'with LIBRARY argument' => [
['LIST', false, 0, 'libname'],
['LIST', 'LIBRARY', 'libname'],
],
'with all arguments' => [
['LIST', true, 2, 'libname'],
['LIST', 'WITHCODE', 'v', 'v', 'LIBRARY', 'libname'],
],
];
}
public function responseProvider(): array
{
return [
'with non-LIST subcommand' => [
['LOAD', 'lib'],
[['key', 'value']],
[['key', 'value']],
],
'with LIST subcommand' => [
['LIST'],
[['key', 'value', ['key1', 'value1']]],
[['key' => 'value', 2 => ['key1' => 'value1']]],
],
];
}
}