Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1a8b049

Browse files
Merge branch 'hotfix/ttl_return'
2 parents de139e8 + 1b62414 commit 1a8b049

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

README.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,13 +1124,13 @@ var_dump($redis->sort('s', array('sort' => 'desc', 'store' => 'out'))); // (int)
11241124

11251125
### ttl, pttl
11261126
-----
1127-
_**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.
1127+
_**Description**_: Returns the time to live left for a given key in seconds (ttl), or milliseconds (pttl).
11281128

11291129
##### *Parameters*
11301130
*Key*: key
11311131

11321132
##### *Return value*
1133-
Long, the time left to live in seconds.
1133+
*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.
11341134

11351135
##### *Example*
11361136
~~~

tests/TestRedis.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,18 +1626,26 @@ public function testlGetRange() {
16261626
// }
16271627

16281628
public function testdbSize() {
1629-
$this->assertTrue($this->redis->flushDB());
1630-
$this->redis->set('x', 'y');
1631-
$this->assertTrue($this->redis->dbSize() === 1);
1629+
$this->assertTrue($this->redis->flushDB());
1630+
$this->redis->set('x', 'y');
1631+
$this->assertTrue($this->redis->dbSize() === 1);
16321632
}
16331633

16341634
public function testttl() {
1635-
$this->redis->set('x', 'y');
1636-
$this->redis->setTimeout('x', 5);
1637-
for($i = 5; $i > 0; $i--) {
1638-
$this->assertEquals($i, $this->redis->ttl('x'));
1639-
sleep(1);
1640-
}
1635+
$this->redis->set('x', 'y');
1636+
$this->redis->setTimeout('x', 5);
1637+
for($i = 5; $i > 0; $i--) {
1638+
$this->assertEquals($i, $this->redis->ttl('x'));
1639+
sleep(1);
1640+
}
1641+
1642+
// A key with no TTL
1643+
$this->redis->del('x'); $this->redis->set('x', 'bar');
1644+
$this->assertEquals($this->redis->ttl('x'), -1);
1645+
1646+
// A key that doesn't exist
1647+
$this->redis->del('x');
1648+
$this->assertEquals($this->redis->ttl('x'), -2);
16411649
}
16421650

16431651
public function testPersist() {

0 commit comments

Comments
 (0)