当前位置: 首页>>代码示例>>PHP>>正文


PHP Client::ttl方法代码示例

本文整理汇总了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);
 }
开发者ID:becquerel,项目名称:redis-copy,代码行数:33,代码来源:RedisCopy.php

示例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;
 }
开发者ID:wopp,项目名称:keyvalue-bundle,代码行数:14,代码来源:KeyValueServiceRedisImpl.php

示例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;
 }
开发者ID:simon-downes,项目名称:spf,代码行数:36,代码来源:Redis.php

示例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));
             }
         }
     }
 }
开发者ID:likewinter,项目名称:queue-throttle,代码行数:20,代码来源:Throttle.php

示例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);
                 }
             }
         }
     });
 }
开发者ID:jced-artem,项目名称:test_game,代码行数:23,代码来源:Cache.php


注:本文中的Predis\Client::ttl方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。