diff options
author | michael-grunder <michael.grunder@gmail.com> | 2013-08-01 01:58:01 +0400 |
---|---|---|
committer | michael-grunder <michael.grunder@gmail.com> | 2013-08-01 01:58:01 +0400 |
commit | 1a8b049d4f56c22308189baafb58dfe03dcdab3a (patch) | |
tree | 3a07868353d5da380010b625f51fa246a4c75f67 | |
parent | de139e83def52554cb8718fe560ba515bcc565b0 (diff) | |
parent | 1b624141c052d89d4b0bd17815768dcb50520edb (diff) |
Merge branch 'hotfix/ttl_return'ttl_return
-rw-r--r-- | README.markdown | 4 | ||||
-rw-r--r-- | tests/TestRedis.php | 26 |
2 files changed, 19 insertions, 11 deletions
diff --git a/README.markdown b/README.markdown index 0f4d9cb4..ce978c05 100644 --- a/README.markdown +++ b/README.markdown @@ -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* ~~~ diff --git a/tests/TestRedis.php b/tests/TestRedis.php index 70d38355..6091a94d 100644 --- a/tests/TestRedis.php +++ b/tests/TestRedis.php @@ -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() { |