本文整理匯總了PHP中Redis::setTimeout方法的典型用法代碼示例。如果您正苦於以下問題:PHP Redis::setTimeout方法的具體用法?PHP Redis::setTimeout怎麽用?PHP Redis::setTimeout使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Redis
的用法示例。
在下文中一共展示了Redis::setTimeout方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: prepend
/**
* @param mixed $value
*
* @return RedisNoSQLList
*/
public function prepend($value)
{
$this->redis->lpush($this->key, $value);
if ($this->timeout) {
$this->redis->setTimeout($this->key, $this->timeout);
}
return $this;
}
示例2: increment
public static function increment($host)
{
$count = self::$redis->incrBy(self::$prefix . $host, 1);
if (self::$redis->get(self::$prefix . $host) == 1) {
self::$redis->setTimeout(self::$prefix . $host, self::$ttl);
}
return $count;
}
示例3: setJson
/**
* 設置值(string)會將$value自動轉為json格式
* @param string $key KEY名稱
* @param string|array $value 獲取得到的數據
* @param int $timeOut 時間
* @return bool
*/
public function setJson($key, $value, $timeOut = 0)
{
$value = json_encode($value);
$retRes = $this->redis->set($key, $value);
if ($timeOut > 0) {
$this->redis->setTimeout($key, $timeOut);
}
return $retRes;
}
示例4: addValue
protected function addValue($key, $value, $expires = 0)
{
$r = $this->redis->setnx($key, $value);
if ($r && $expires) {
$this->redis->setTimeout($key, $expires);
}
return $r;
}
示例5: testttl
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);
}
}
示例6: set
/**
* 設置值
* @param string $key KEY名稱
* @param string|array $value 獲取得到的數據
* @param int $timeOut 時間
* @return bool
*/
public function set($key, $value, $timeOut = 0)
{
$value = json_encode($value);
$retRes = parent::set($key, $value);
if ($timeOut > 0) {
parent::setTimeout($key, $timeOut);
}
return $retRes;
}
示例7: testPersist
public function testPersist()
{
$this->redis->set('x', 'y');
$this->redis->setTimeout('x', 100);
$this->assertTrue(TRUE === $this->redis->persist('x'));
// true if there is a timeout
$this->assertTrue(-1 === $this->redis->ttl('x'));
// -1: timeout has been removed.
$this->assertTrue(FALSE === $this->redis->persist('x'));
// false if there is no timeout
$this->redis->delete('x');
$this->assertTrue(FALSE === $this->redis->persist('x'));
// false if the key doesn’t exist.
}
示例8: add
/**
* Add to the cache
*
* Add a new variable to the cache that you will then be able
* to retrieve using the $this->get($name) method.
*
* @param string $name The name of the cache variable to store.
* @param string $value The value of the cache variable to store.
* @param integer $expire When should it expire? Default: 900 seconds.
*
* @return boolean Depending on the success of the operation,
* either true or false.
*/
public function add($name, $value, $expiry = 900)
{
$this->redis->add($name, serialize($value));
$this->redis->setTimeout($name, $expiry);
}