From 1b624141c052d89d4b0bd17815768dcb50520edb Mon Sep 17 00:00:00 2001 From: michael-grunder Date: Wed, 31 Jul 2013 14:57:26 -0700 Subject: Update documentation and unit tests for TTL/PTTL Addresses #358 --- README.markdown | 4 ++-- 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() { -- cgit v1.2.3