Update documentation and unit tests for TTL/PTTL

Addresses #358
This commit is contained in:
michael-grunder
2013-07-31 14:57:26 -07:00
parent de139e83de
commit 1b624141c0
2 changed files with 19 additions and 11 deletions

View File

@@ -1124,13 +1124,13 @@ var_dump($redis->sort('s', array('sort' => 'desc', 'store' => 'out'))); // (int)
### ttl, pttl
-----
_**Description**_: Returns the time to live left for a given key, in seconds. If the key doesn't exist, `FALSE` is returned. pttl returns a time in milliseconds.
_**Description**_: Returns the time to live left for a given key in seconds (ttl), or milliseconds (pttl).
##### *Parameters*
*Key*: key
##### *Return value*
Long, the time left to live in seconds.
*LONG*: The time to live in seconds. If the key has no ttl, `-1` will be returned, and `-2` if the key doesn't exist.
##### *Example*
~~~

View File

@@ -1626,18 +1626,26 @@ class Redis_Test extends TestSuite
// }
public function testdbSize() {
$this->assertTrue($this->redis->flushDB());
$this->redis->set('x', 'y');
$this->assertTrue($this->redis->dbSize() === 1);
$this->assertTrue($this->redis->flushDB());
$this->redis->set('x', 'y');
$this->assertTrue($this->redis->dbSize() === 1);
}
public function testttl() {
$this->redis->set('x', 'y');
$this->redis->setTimeout('x', 5);
for($i = 5; $i > 0; $i--) {
$this->assertEquals($i, $this->redis->ttl('x'));
sleep(1);
}
$this->redis->set('x', 'y');
$this->redis->setTimeout('x', 5);
for($i = 5; $i > 0; $i--) {
$this->assertEquals($i, $this->redis->ttl('x'));
sleep(1);
}
// A key with no TTL
$this->redis->del('x'); $this->redis->set('x', 'bar');
$this->assertEquals($this->redis->ttl('x'), -1);
// A key that doesn't exist
$this->redis->del('x');
$this->assertEquals($this->redis->ttl('x'), -2);
}
public function testPersist() {