本文整理汇总了PHP中Predis\Client::ttl方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::ttl方法的具体用法?PHP Client::ttl怎么用?PHP Client::ttl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Predis\Client
的用法示例。
在下文中一共展示了Client::ttl方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: copy
/**
* function that takes all keys from source redis, dumps them and imports to the new redis
*/
public function copy()
{
// retrieve all keys from source redis
$keys = $this->source->keys('*');
$this->out("Processing %d REDIS keys ...", count($keys), true);
$hundred = 0;
$step = 0;
foreach ($keys as $key) {
// check for ignored keys and skip the key if it should be ignored
foreach ($this->ignoredPrefixes as $ignoredPrefix) {
if (strpos($key, $ignoredPrefix) !== false) {
$this->out('.');
continue 2;
// continue with the next key
}
}
try {
$ttl = max(0, (int) $this->source->ttl($key));
$serializedValue = $this->source->dump($key);
$this->destination->restore($key, $ttl, $serializedValue);
} catch (Exception $e) {
$this->out(PHP_EOL . 'ERROR: ' . $key . PHP_EOL);
}
if ($step++ % 100 == 0) {
$this->out(PHP_EOL . $hundred++ . ': ');
}
$this->out('o');
}
$this->out(PHP_EOL . PHP_EOL);
}
示例2: get
/**
* {@inheritDoc}
*/
public function get($key, $namespace = KeyValue::DEFAULT_NAMESPACE)
{
$value = $this->getValue($key, $namespace);
$effectiveKey = $this->buildKey($key, $namespace);
$expiration = $this->redisClient->ttl($effectiveKey);
$keyValue = new KeyValue($key, $value, $namespace);
if ($expiration !== -1) {
$keyValue->setExpirationInSeconds($expiration);
}
return $keyValue;
}
示例3: refreshIndex
/**
* Refresh the local cache index from the cache.
* The index is stored in Redis as a set with the key <prefix>::index.
* Items are added and removed from the index via the write and delete but
* are also expired automatically by Redis. This function reads the index
* set and checks the TTL of each key, removing those that no longer exist
* from the index.
* @return self
*/
public function refreshIndex()
{
if ($this->indexing) {
$expired = array();
foreach ($this->store->sMembers("{$this->prefix}::index") as $k) {
switch ($this->index[$k] = $this->store->ttl($k)) {
case -2:
$expired[] = $k;
unset($this->index[$k]);
break;
case -1:
// We're not running Redis 2.8 yet so we always get -1
// we'll assume all keys have an expiry and remove any without in order to keep the index clean
//$this->index[$k] = 2147483648;
$expired[] = $k;
unset($this->index[$k]);
break;
default:
$this->index[$k] = time() + $this->index[$k];
}
}
foreach ($expired as $k) {
$this->removeFromIndex($k);
}
}
return $this;
}
示例4: work
public function work()
{
foreach ($this->limits as $index => $limit) {
$counterName = "queue:{$this->tube}:throttle:{$index}";
$started = (bool) $this->redis->setnx($counterName, $limit['requests']);
$counter = $this->redis->get($counterName);
if ($started) {
$this->redis->transaction(function (MultiExec $transaction) use($counterName, $limit) {
$transaction->expire($counterName, $limit['seconds']);
$transaction->decr($counterName);
});
} else {
if ($counter > 1) {
$this->redis->decr($counterName);
} else {
$this->pheanstalk->pauseTube($this->tube, $this->redis->ttl($counterName));
}
}
}
}
示例5: flush
/**
*
*/
public function flush()
{
$this->client->transaction(function () {
foreach ($this->buffer as $name => $options) {
$ttl = $this->client->ttl($name);
$exists = $this->client->exists($name);
$this->client->set($name, $options['value']);
if ($options['expire'] > 0) {
$this->client->expire($name, $options['expire']);
}
if ($options['expire'] < 0) {
if (!$exists || $ttl < 0) {
$this->client->expireat($name, time() + $options['expire'] * -1);
} else {
$this->client->expire($name, $ttl);
}
}
}
});
}