本文整理汇总了PHP中Redis::ttl方法的典型用法代码示例。如果您正苦于以下问题:PHP Redis::ttl方法的具体用法?PHP Redis::ttl怎么用?PHP Redis::ttl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Redis
的用法示例。
在下文中一共展示了Redis::ttl方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getTTL
public function getTTL($key)
{
if (!$this->isConnected()) {
return false;
}
return $this->redis->ttl($key);
}
示例2: getMeta
/**
* @inheritdoc
*/
public function getMeta($id)
{
if ($value = $this->get($id)) {
return ['expire' => time() + $this->driver->ttl($id), 'data' => $value];
}
return false;
}
示例3: get_metadata
/**
* Get cache metadata
*
* @param string Cache key
* @return array
*/
public function get_metadata($key)
{
$value = $this->get($key);
if ($value !== FALSE) {
return array('expire' => time() + $this->_redis->ttl($key), 'data' => $value);
}
return FALSE;
}
示例4: get_metadata
/**
* Get cache metadata.
*
* @param string $key Cache key
*
* @return array
*/
public function get_metadata($key)
{
$value = $this->get($key);
if ($value !== false) {
return ['expire' => time() + $this->_redis->ttl($key), 'data' => $value];
}
return false;
}
示例5: setCached
protected function setCached(Bookmark $bookmark, $redisKey)
{
if ($this->redis !== null) {
$this->redis->hSet($redisKey, $bookmark->url, 1);
if ($this->redis->ttl($redisKey) < 0) {
$this->redis->expire($redisKey, 4 * 7 * 24 * 60 * 60);
}
}
}
示例6: 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);
}
}
示例7: get_metadata
/**
* Get Cache Metadata
*
* @param string $id Key to get cache metadata on
* @param const $scope Cache::LOCAL_SCOPE or Cache::GLOBAL_SCOPE
* for local or global scoping of the cache item
* @return mixed Cache item metadata
*/
public function get_metadata($key, $scope = Cache::LOCAL_SCOPE)
{
$data = $data = unserialize($this->_redis->get($this->unique_key($key, $scope)));
$key = $this->unique_key($key, $scope);
if (is_array($data)) {
list($data, $time) = $data;
return array('expire' => ee()->localize->now + $this->_redis->ttl($key), 'mtime' => $time, 'data' => $data);
}
return FALSE;
}
示例8: setOverwritesExistingEntryWithNewUnlimitedLifetime
/**
* @test Implementation
*/
public function setOverwritesExistingEntryWithNewUnlimitedLifetime()
{
$this->setUpBackend();
$this->setUpRedis();
$data = 'data';
$identifier = 'identifier' . uniqid();
$lifetime = 42;
$this->backend->set($identifier, $data, array(), $lifetime);
$this->backend->set($identifier, $data, array(), 0);
$lifetimeRegisteredInBackend = $this->redis->ttl('identData:' . $identifier);
$this->assertSame(31536000, $lifetimeRegisteredInBackend);
}
示例9: 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.
}
示例10: timeleft
/**
* 获取该k的生存时间,默认返回秒数
* @param bool $inMs 为TRUE时返回ms数(1s=1000ms),为FALSE时,只返回秒数部分(如果有毫秒部分被省略)
* @return 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.
*/
public function timeleft($inMs = FALSE)
{
try {
if ($inMs) {
return $this->rd->pttl($this->k);
} else {
return $this->rd->ttl($this->k);
}
} catch (\RedisException $e) {
if ($this->reconnRedis()) {
if ($inMs) {
return $this->rd->pttl($this->k);
} else {
return $this->rd->ttl($this->k);
}
}
}
return FALSE;
}
示例11: ttl
/**
* @param string $key
* @return int
*/
public function ttl($key)
{
$this->_useCnt++;
return $this->_wrapBoolReturn(function () use($key) {
return parent::ttl($key);
});
}
示例12: die
<?php
$redis = new \Redis();
$ok = $redis->connect('127.0.0.1');
$redis->select(9);
if (!$ok) {
die("redis connect failed");
}
$redis->select(9);
var_dump($key = $redis->keys("*")[0]);
//$redis->setTimeout($key, 1000);
var_dump($redis->ttl($key));
示例13:
* Time: 下午4:32
*/
$redis = new \Redis();
$redis->connect('127.0.0.1', 6379);
$key = 'test-expire-key';
$redis->expire($key, 60);
//使用秒为单位
$redis->pExpire($key, 60000);
//使用毫秒作为单位
$redis->expireAt($key, 1476868380);
//使用Unix timestamp,指定时间过期
$redis->pExpireAt($key, 1476868380000.0);
//使用Unix timestamp在指定时间过期,区别是毫秒作为单位
$redis->persist($key);
//移除给定key的生存时间
$redis->ttl($key);
//返回key剩余的过期时间,使用秒为单位
$redis->pttl($key);
//返回key剩余的过期时间,使用毫秒作为单位
$redis->watch($key2);
$ret = $redis->multi(Redis::MULTI)->get($key)->incr($key1)->del($key2)->exec();
$pip->incr('a');
$pip->get('test-num2');
$pip->incr('b');
$pip->del('a');
$ret = $pip->exec();
var_dump($ret);
exit;
$ret = $redis->incr('test-num2')->incr('test-num2')->exec();
exit('aa' . $redis->get('test-num2'));
$redis->multi(Redis::PIPELINE);
示例14: Redis
<?php
$redis = new Redis();
$redis->connect('127.0.0.1', '6379');
$redis->select(0);
$redis->setex("key", 10, "this is a test");
echo $redis->get("key");
echo "\n";
sleep(6);
echo $redis->ttl("key");
示例15: ttl
/**
* 查询某个key的生存时间
* @param $key string 要查询的key名
*/
public static function ttl($key)
{
$redis = new \Redis();
$redis->connect(self::_HOST, self::_PORT);
$return = null;
$return = $redis->ttl($key);
$redis->close();
$redis = null;
return $return;
}