示例#1
0
 /**
  * Sets an expiration date (a timeout) on an item.
  *
  * @param string $key The key that will disappear.
  * @param int $ttl The key's remaining Time To Live, in seconds.
  *
  * @return bool TRUE in case of success, FALSE in case of failure.
  * @link http://redis.io/commands/expire
  * @example
  * <pre>
  * $redis->set('x', '42');
  * $redis->setTimeout('x', 3); // x will disappear in 3 seconds.
  * sleep(5); // wait 5 seconds
  * $redis->get('x'); // will return `FALSE`, as 'x' has expired.
  * </pre>
  */
 public function expire($key, $ttl)
 {
     try {
         return $this->client->expire($key, $ttl);
     } catch (Exception $e) {
         return $this->handleException($e, __FUNCTION__, func_get_args());
     }
 }
示例#2
0
 /**
  * Test persisting a key
  */
 public function testPersist()
 {
     $this->redis->del('testPersist');
     $isPersisted = $this->redis->persist('testPersist');
     $this->assertInternalType('bool', $isPersisted);
     $this->assertFalse($isPersisted);
     $this->redis->set('testPersist', 'someValue');
     $this->assertFalse($this->redis->persist('testPersist'));
     $this->redis->expire('testPersist', 1);
     $isPersisted = $this->redis->persist('testPersist');
     $this->assertInternalType('bool', $isPersisted);
     $this->assertTrue($isPersisted);
     sleep(2);
     $this->assertEquals('someValue', $this->redis->get('testPersist'));
 }
示例#3
0
 /**
  * Sets an expiration date (a timeout) on an item.
  *
  * @param string $key The key that will disappear.
  * @param int $ttl The key's remaining Time To Live, in seconds.
  *
  * @return bool TRUE in case of success, FALSE in case of failure.
  * @link http://redis.io/commands/expire
  * @example
  * <pre>
  * $redis->set('x', '42');
  * $redis->setTimeout('x', 3); // x will disappear in 3 seconds.
  * sleep(5); // wait 5 seconds
  * $redis->get('x'); // will return `FALSE`, as 'x' has expired.
  * </pre>
  */
 public function expire($key, $ttl)
 {
     $this->appendToLog('EXPIRE ' . $key . ' ' . $ttl);
     return $this->client->expire($key, $ttl);
 }