本文整理汇总了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);
}