Skip to content

Commit

Permalink
Added support for Redis 7.0 arguments (#1359)
Browse files Browse the repository at this point in the history
  • Loading branch information
vladvildanov committed Aug 10, 2023
1 parent 4172d22 commit 1b2fd52
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/ClientContextInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@
* @method $this evalsha($script, $numkeys, $keyOrArg1 = null, $keyOrArgN = null)
* @method $this evalsha_ro(string $sha1, array $keys, ...$argument)
* @method $this script($subcommand, $argument = null)
* @method $this shutdown(bool $noSave = null, bool $now = false, bool $force = false, bool $abort = false)
* @method $this auth($password)
* @method $this echo($message)
* @method $this ping($message = null)
Expand Down
1 change: 1 addition & 0 deletions src/ClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@
* @method mixed evalsha(string $script, int $numkeys, string ...$keyOrArg = null)
* @method mixed evalsha_ro(string $sha1, array $keys, ...$argument)
* @method mixed script($subcommand, $argument = null)
* @method Status shutdown(bool $noSave = null, bool $now = false, bool $force = false, bool $abort = false)
* @method mixed auth(string $password)
* @method string echo(string $message)
* @method mixed ping(string $message = null)
Expand Down
32 changes: 32 additions & 0 deletions src/Command/Redis/SHUTDOWN.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,36 @@ public function getId()
{
return 'SHUTDOWN';
}

/**
* {@inheritdoc}
*/
public function setArguments(array $arguments)
{
if (empty($arguments)) {
parent::setArguments($arguments);

return;
}

$processedArguments = [];

if (array_key_exists(0, $arguments) && null !== $arguments[0]) {
$processedArguments[] = ($arguments[0]) ? 'SAVE' : 'NOSAVE';
}

if (array_key_exists(1, $arguments) && false !== $arguments[1]) {
$processedArguments[] = 'NOW';
}

if (array_key_exists(2, $arguments) && false !== $arguments[2]) {
$processedArguments[] = 'FORCE';
}

if (array_key_exists(3, $arguments) && false !== $arguments[3]) {
$processedArguments[] = 'ABORT';
}

parent::setArguments($processedArguments);
}
}
41 changes: 38 additions & 3 deletions tests/Predis/Command/Redis/SHUTDOWN_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,48 @@ protected function getExpectedId(): string
}

/**
* @dataProvider argumentsProvider
* @group disconnected
*/
public function testFilterArguments(): void
public function testFilterArguments(array $actualArguments, array $expectedResponse): void
{
$command = $this->getCommand();
$command->setArguments([]);
$command->setArguments($actualArguments);

$this->assertSame([], $command->getArguments());
$this->assertSame($expectedResponse, $command->getArguments());
}

public function argumentsProvider(): array
{
return [
'with no arguments' => [
[],
[],
],
'with SAVE argument' => [
[true],
['SAVE'],
],
'with NOSAVE argument' => [
[false],
['NOSAVE'],
],
'with NOW argument' => [
[null, true],
['NOW'],
],
'with FORCE argument' => [
[null, false, true],
['FORCE'],
],
'with ABORT argument' => [
[null, false, false, true],
['ABORT'],
],
'with all arguments' => [
[true, true, true, true],
['SAVE', 'NOW', 'FORCE', 'ABORT'],
],
];
}
}

0 comments on commit 1b2fd52

Please sign in to comment.