mirror of
https://github.com/predis/predis.git
synced 2026-08-31 12:43:31 +00:00
add TOUCH command (#767)
This commit is contained in:
@@ -115,6 +115,7 @@ use Predis\Response\Status;
|
||||
* @method array sscan(string $key, int $cursor, array $options = null)
|
||||
* @method string[] sunion(array|string $keys)
|
||||
* @method int sunionstore(string $destination, array|string $keys)
|
||||
* @method int touch(string[]|string $keyOrKeys, string ...$keys = null)
|
||||
* @method int zadd(string $key, array $membersAndScoresDictionary)
|
||||
* @method int zcard(string $key)
|
||||
* @method string zcount(string $key, int|string $min, int|string $max)
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (c) Daniele Alessandri <suppakilla@gmail.com>
|
||||
*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* @link http://redis.io/commands/touch
|
||||
*
|
||||
* @author Daniele Alessandri <suppakilla@gmail.com>
|
||||
*/
|
||||
class TOUCH extends RedisCommand
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return 'TOUCH';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setArguments(array $arguments)
|
||||
{
|
||||
$arguments = self::normalizeArguments($arguments);
|
||||
|
||||
parent::setArguments($arguments);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (c) Daniele Alessandri <suppakilla@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis;
|
||||
|
||||
/**
|
||||
* @group commands
|
||||
* @group realm-server
|
||||
*/
|
||||
class TOUCH_Test extends PredisCommandTestCase
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedCommand(): string
|
||||
{
|
||||
return 'Predis\Command\Redis\TOUCH';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedId(): string
|
||||
{
|
||||
return 'TOUCH';
|
||||
}
|
||||
|
||||
/**
|
||||
* @requiresRedisVersion >= 3.2.1
|
||||
*
|
||||
* @group disconnected
|
||||
*/
|
||||
public function testFilterArguments(): void
|
||||
{
|
||||
$arguments = ['key1', 'key2', 'key3'];
|
||||
$expected = ['key1', 'key2', 'key3'];
|
||||
|
||||
$command = $this->getCommand();
|
||||
$command->setArguments($arguments);
|
||||
$this->assertSame($expected, $command->getArguments());
|
||||
}
|
||||
|
||||
/**
|
||||
* @requiresRedisVersion >= 3.2.1
|
||||
*
|
||||
* @group disconnected
|
||||
*/
|
||||
public function testFilterArgumentsAsSingleArray(): void
|
||||
{
|
||||
$arguments = [['key1', 'key2', 'key3']];
|
||||
$expected = ['key1', 'key2', 'key3'];
|
||||
|
||||
$command = $this->getCommand();
|
||||
$command->setArguments($arguments);
|
||||
|
||||
$this->assertSame($expected, $command->getArguments());
|
||||
}
|
||||
|
||||
/**
|
||||
* @requiresRedisVersion >= 3.2.1
|
||||
*
|
||||
* @group disconnected
|
||||
*/
|
||||
public function testParseResponse(): void
|
||||
{
|
||||
$command = $this->getCommand();
|
||||
|
||||
$this->assertSame(10, $command->parseResponse(10));
|
||||
}
|
||||
|
||||
/**
|
||||
* @requiresRedisVersion >= 3.2.1
|
||||
*
|
||||
* @group connected
|
||||
*/
|
||||
public function testReturnsNumberOfDeletedKeys(): void
|
||||
{
|
||||
$redis = $this->getClient();
|
||||
|
||||
$this->assertSame(0, $redis->touch('foo'));
|
||||
|
||||
$redis->set('foo', 'bar');
|
||||
$this->assertSame(1, $redis->touch('foo'));
|
||||
$this->assertSame(1, $redis->touch('foo', 'hoge'));
|
||||
|
||||
$redis->set('hoge', 'piyo');
|
||||
$this->assertSame(1, $redis->touch('foo'));
|
||||
$this->assertSame(2, $redis->touch('foo', 'hoge'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user