mirror of
https://github.com/predis/predis.git
synced 2026-08-24 21:49:33 +00:00
d0b431016d
While command classes define how the client should filter arguments or parse responses, key prefixing depends on the actual command signature as defined by Redis so it really is something that should be handled separately as the norm. Developers can define new handlers or override existing ones, but they can still define the key prefixing logic inside their command classes by implementing Predis\Command\PrefixableCommandInterface: the key prefix processor will just use that by overriding any defined handler.
117 lines
2.7 KiB
PHP
117 lines
2.7 KiB
PHP
<?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;
|
|
|
|
use PHPUnit_Framework_TestCase as StandardTestCase;
|
|
|
|
/**
|
|
* @group commands
|
|
* @group realm-string
|
|
*/
|
|
class StringPreciseSetExpireTest extends CommandTestCase
|
|
{
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
protected function getExpectedCommand()
|
|
{
|
|
return 'Predis\Command\StringPreciseSetExpire';
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
protected function getExpectedId()
|
|
{
|
|
return 'PSETEX';
|
|
}
|
|
|
|
/**
|
|
* @group disconnected
|
|
*/
|
|
public function testFilterArguments()
|
|
{
|
|
$arguments = array('key', 10, 'hello');
|
|
$expected = array('key', 10, 'hello');
|
|
|
|
$command = $this->getCommand();
|
|
$command->setArguments($arguments);
|
|
|
|
$this->assertSame($expected, $command->getArguments());
|
|
}
|
|
|
|
/**
|
|
* @group disconnected
|
|
*/
|
|
public function testParseResponse()
|
|
{
|
|
$this->assertTrue($this->getCommand()->parseResponse(true));
|
|
}
|
|
|
|
/**
|
|
* @group connected
|
|
*/
|
|
public function testCreatesNewKeyAndSetsTTL()
|
|
{
|
|
$redis = $this->getClient();
|
|
|
|
$this->assertTrue($redis->psetex('foo', 10000, 'bar'));
|
|
$this->assertTrue($redis->exists('foo'));
|
|
$this->assertEquals(10, $redis->ttl('foo'));
|
|
}
|
|
|
|
/**
|
|
* @group connected
|
|
* @group slow
|
|
*/
|
|
public function testKeyExpiresAfterTTL()
|
|
{
|
|
$redis = $this->getClient();
|
|
|
|
$redis->psetex('foo', 50, 'bar');
|
|
$this->sleep(0.5);
|
|
$this->assertFalse($redis->exists('foo'));;
|
|
}
|
|
|
|
/**
|
|
* @group connected
|
|
* @expectedException Predis\Response\ServerException
|
|
* @expectedExceptionMessage ERR value is not an integer or out of range
|
|
*/
|
|
public function testThrowsExceptionOnNonIntegerTTL()
|
|
{
|
|
$this->getClient()->psetex('foo', 2.5, 'bar');
|
|
}
|
|
|
|
/**
|
|
* @group connected
|
|
* @expectedException Predis\Response\ServerException
|
|
* @expectedExceptionMessage ERR invalid expire time in SETEX
|
|
* @todo Should not Redis return PSETEX instead of SETEX here?
|
|
*/
|
|
public function testThrowsExceptionOnZeroTTL()
|
|
{
|
|
$this->getClient()->psetex('foo', 0, 'bar');
|
|
}
|
|
|
|
/**
|
|
* @group connected
|
|
* @expectedException Predis\Response\ServerException
|
|
* @expectedExceptionMessage ERR invalid expire time in SETEX
|
|
* @todo Should not Redis return PSETEX instead of SETEX here?
|
|
*/
|
|
public function testThrowsExceptionOnNegativeTTL()
|
|
{
|
|
$this->getClient()->psetex('foo', -10000, 'bar');
|
|
}
|
|
}
|