Added support for GETDEL command (#869)

Co-authored-by: Vladyslav Vildanov <vladyslavvildanov@Vladyslav-Vildanov-MacBook-Pro.local>
This commit is contained in:
Vladyslav Vildanov
2022-12-20 19:32:58 +02:00
committed by GitHub
parent 72bc11eb63
commit 4a77aea9ef
4 changed files with 78 additions and 0 deletions
+1
View File
@@ -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)
+1
View File
@@ -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)
+13
View File
@@ -0,0 +1,13 @@
<?php
namespace Predis\Command\Redis;
use Predis\Command\Command as RedisCommand;
class GETDEL extends RedisCommand
{
public function getId()
{
return 'GETDEL';
}
}
@@ -0,0 +1,63 @@
<?php
namespace Predis\Command\Redis;
class GETDEL_Test extends PredisCommandTestCase
{
/**
* @inheritDoc
*/
protected function getExpectedCommand(): string
{
return GETDEL::class;
}
/**
* @inheritDoc
*/
protected function getExpectedId(): string
{
return 'GETDEL';
}
/**
* @group disconnected
*/
public function testFilterArguments(): void
{
$arguments = ['key'];
$expected = ['key'];
$command = $this->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));
}
}