From 4a77aea9efe63e9cca251aeff7c603b6b76a09cc Mon Sep 17 00:00:00 2001 From: Vladyslav Vildanov <117659936+vladvildanov@users.noreply.github.com> Date: Tue, 20 Dec 2022 19:32:58 +0200 Subject: [PATCH] Added support for GETDEL command (#869) Co-authored-by: Vladyslav Vildanov --- src/ClientContextInterface.php | 1 + src/ClientInterface.php | 1 + src/Command/Redis/GETDEL.php | 13 +++++ tests/Predis/Command/Redis/GETDEL_Test.php | 63 ++++++++++++++++++++++ 4 files changed, 78 insertions(+) create mode 100644 src/Command/Redis/GETDEL.php create mode 100644 tests/Predis/Command/Redis/GETDEL_Test.php diff --git a/src/ClientContextInterface.php b/src/ClientContextInterface.php index 48c53926..57475991 100644 --- a/src/ClientContextInterface.php +++ b/src/ClientContextInterface.php @@ -48,6 +48,7 @@ use Predis\Command\CommandInterface; * @method $this get($key) * @method $this getbit($key, $offset) * @method $this getrange($key, $start, $end) + * @method $this getdel(string $key) * @method $this getset($key, $value) * @method $this incr($key) * @method $this incrby($key, $increment) diff --git a/src/ClientInterface.php b/src/ClientInterface.php index 5ec9ed03..a223b550 100644 --- a/src/ClientInterface.php +++ b/src/ClientInterface.php @@ -57,6 +57,7 @@ use Predis\Response\Status; * @method string|null get(string $key) * @method int getbit(string $key, $offset) * @method string getrange(string $key, $start, $end) + * @method string getdel(string $key) * @method string|null getset(string $key, $value) * @method int incr(string $key) * @method int incrby(string $key, int $increment) diff --git a/src/Command/Redis/GETDEL.php b/src/Command/Redis/GETDEL.php new file mode 100644 index 00000000..f860f08c --- /dev/null +++ b/src/Command/Redis/GETDEL.php @@ -0,0 +1,13 @@ +getCommand(); + $command->setArguments($arguments); + + $this->assertSame($expected, $command->getArguments()); + } + + /** + * @group disconnected + */ + public function testParseResponse(): void + { + $this->assertSame(1, $this->getCommand()->parseResponse(1)); + } + + /** + * @group connected + * @return void + * @requiresRedisVersion >= 6.2.0 + */ + public function testReturnsValueForGivenKeyAndDeleteIt(): void + { + $redis = $this->getClient(); + $expectedKey = 'key'; + $expectedValue = 'value'; + + $redis->set($expectedKey, $expectedValue); + + $actualResponse = $redis->getdel($expectedKey); + + $this->assertSame($expectedValue, $actualResponse); + $this->assertNull($redis->get($expectedKey)); + } +}