1
|
<?php
|
2
|
|
3
|
/*
|
4
|
* This file is part of the Predis package.
|
5
|
*
|
6
|
* (c) Daniele Alessandri <suppakilla@gmail.com>
|
7
|
*
|
8
|
* For the full copyright and license information, please view the LICENSE
|
9
|
* file that was distributed with this source code.
|
10
|
*/
|
11
|
|
12
|
namespace Predis\Command;
|
13
|
|
14
|
/**
|
15
|
* @group commands
|
16
|
* @group realm-key
|
17
|
*/
|
18
|
class KeyPersistTest extends PredisCommandTestCase
|
19
|
{
|
20
|
/**
|
21
|
* {@inheritdoc}
|
22
|
*/
|
23
|
protected function getExpectedCommand()
|
24
|
{
|
25
|
return 'Predis\Command\KeyPersist';
|
26
|
}
|
27
|
|
28
|
/**
|
29
|
* {@inheritdoc}
|
30
|
*/
|
31
|
protected function getExpectedId()
|
32
|
{
|
33
|
return 'PERSIST';
|
34
|
}
|
35
|
|
36
|
/**
|
37
|
* @group disconnected
|
38
|
*/
|
39
|
public function testFilterArguments()
|
40
|
{
|
41
|
$arguments = array('key');
|
42
|
$expected = array('key');
|
43
|
|
44
|
$command = $this->getCommand();
|
45
|
$command->setArguments($arguments);
|
46
|
|
47
|
$this->assertSame($expected, $command->getArguments());
|
48
|
}
|
49
|
|
50
|
/**
|
51
|
* @group disconnected
|
52
|
*/
|
53
|
public function testParseResponse()
|
54
|
{
|
55
|
$command = $this->getCommand();
|
56
|
|
57
|
$this->assertTrue($command->parseResponse(1));
|
58
|
$this->assertFalse($command->parseResponse(0));
|
59
|
}
|
60
|
|
61
|
/**
|
62
|
* @group disconnected
|
63
|
*/
|
64
|
public function testPrefixKeys()
|
65
|
{
|
66
|
$arguments = array('key');
|
67
|
$expected = array('prefix:key');
|
68
|
|
69
|
$command = $this->getCommandWithArgumentsArray($arguments);
|
70
|
$command->prefixKeys('prefix:');
|
71
|
|
72
|
$this->assertSame($expected, $command->getArguments());
|
73
|
}
|
74
|
|
75
|
/**
|
76
|
* @group disconnected
|
77
|
*/
|
78
|
public function testPrefixKeysIgnoredOnEmptyArguments()
|
79
|
{
|
80
|
$command = $this->getCommand();
|
81
|
$command->prefixKeys('prefix:');
|
82
|
|
83
|
$this->assertSame(array(), $command->getArguments());
|
84
|
}
|
85
|
|
86
|
/**
|
87
|
* @group connected
|
88
|
*/
|
89
|
public function testRemovesExpireFromKey()
|
90
|
{
|
91
|
$redis = $this->getClient();
|
92
|
|
93
|
$redis->set('foo', 'bar');
|
94
|
$redis->expire('foo', 10);
|
95
|
|
96
|
$this->assertTrue($redis->persist('foo'));
|
97
|
$this->assertSame(-1, $redis->ttl('foo'));
|
98
|
}
|
99
|
|
100
|
/**
|
101
|
* @group connected
|
102
|
*/
|
103
|
public function testReturnsFalseOnNonExpiringKeys()
|
104
|
{
|
105
|
$redis = $this->getClient();
|
106
|
|
107
|
$redis->set('foo', 'bar');
|
108
|
|
109
|
$this->assertFalse($redis->persist('foo'));
|
110
|
}
|
111
|
|
112
|
/**
|
113
|
* @group connected
|
114
|
*/
|
115
|
public function testReturnsFalseOnNonExistentKeys()
|
116
|
{
|
117
|
$redis = $this->getClient();
|
118
|
|
119
|
$this->assertFalse($redis->persist('foo'));
|
120
|
}
|
121
|
}
|