/** * Returns the time to live left for a given key, in seconds. If the key doesn't exist, FALSE is returned. * * @param string $key * * @return int, the time left to live in seconds. * @link http://redis.io/commands/ttl * @example $redis->ttl('key'); */ public function ttl($key) { try { return $this->client->ttl($key); } catch (Exception $e) { return $this->handleException($e, __FUNCTION__, func_get_args()); } }
/** * Test getting the ttl for a key */ public function testTtl() { $this->redis->del('testTtl'); $ttl = $this->redis->ttl('testTtl'); $this->assertInternalType('int', $ttl); $this->assertLessThan(0, $ttl); $this->redis->set('testTtl', 'someValue'); $this->assertLessThan(0, $this->redis->ttl('testTtl')); $this->redis->expire('testTtl', 1); $this->assertGreaterThan(0, $this->redis->ttl('testTtl')); }