diff --git a/src/ClientContextInterface.php b/src/ClientContextInterface.php index 95f1590e..d6b9bb90 100644 --- a/src/ClientContextInterface.php +++ b/src/ClientContextInterface.php @@ -310,6 +310,7 @@ use Predis\Command\Redis\Container\Search\FTCURSOR; * @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) diff --git a/src/ClientInterface.php b/src/ClientInterface.php index 924db1ec..5053c9df 100644 --- a/src/ClientInterface.php +++ b/src/ClientInterface.php @@ -328,6 +328,7 @@ use Predis\Response\Status; * @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) diff --git a/src/Command/Redis/SHUTDOWN.php b/src/Command/Redis/SHUTDOWN.php index 7af576c6..4d2b7479 100644 --- a/src/Command/Redis/SHUTDOWN.php +++ b/src/Command/Redis/SHUTDOWN.php @@ -26,4 +26,36 @@ class SHUTDOWN extends RedisCommand { 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); + } } diff --git a/tests/Predis/Command/Redis/SHUTDOWN_Test.php b/tests/Predis/Command/Redis/SHUTDOWN_Test.php index ddf9f112..533139db 100644 --- a/tests/Predis/Command/Redis/SHUTDOWN_Test.php +++ b/tests/Predis/Command/Redis/SHUTDOWN_Test.php @@ -35,13 +35,48 @@ class SHUTDOWN_Test extends PredisCommandTestCase } /** + * @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'], + ], + ]; } }