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


PHP Redis::expire方法代码示例

本文整理汇总了PHP中Redis::expire方法的典型用法代码示例。如果您正苦于以下问题:PHP Redis::expire方法的具体用法?PHP Redis::expire怎么用?PHP Redis::expire使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Redis的用法示例。


在下文中一共展示了Redis::expire方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: set

 public function set($index, $value)
 {
     $this->redis->lset($this->key, $index, $value);
     if ($this->timeout) {
         $this->redis->expire($this->key, $this->timeout);
     }
     return $this;
 }
开发者ID:justthefish,项目名称:hesper,代码行数:8,代码来源:RedisNoSQLList.php

示例2: acquireLock

 /**
  * {@inheritdoc}
  */
 public function acquireLock($lockId)
 {
     if ($this->conn->setnx($lockId, 1)) {
         $this->conn->expire($lockId, $this->lockTtl);
         return true;
     }
     return false;
 }
开发者ID:warmans,项目名称:dlock,代码行数:11,代码来源:Redis.php

示例3: set

 /**
  * Store a value for a given key in the cache.
  *
  * This method does not check if there is a value available for the given key, may cause unexpected behavior if not.
  * Use has() to prevent this issue.
  *
  * @param string $key
  * @param array  $tags
  * @param mixed  $data
  */
 public function set($key, array $tags, $data)
 {
     $key = $this->redis->prefix($key);
     $this->redis->set($key, $this->encoder->encode($data));
     if (is_int($this->expirationTime) && $this->expirationTime > 0) {
         $this->redis->expire($key, $this->expirationTime);
     }
     foreach ($tags as $tag) {
         $this->redis->sadd($this->redis->prefix($tag), $key);
     }
 }
开发者ID:spiritix,项目名称:lada-cache,代码行数:21,代码来源:Cache.php

示例4: setTTL

 public function setTTL($key, $ttl)
 {
     if (!$this->isConnected()) {
         return false;
     }
     if (!$this->exists($key)) {
         return false;
     }
     if (!is_numeric($ttl)) {
         throw new InvalidTtlException($ttl);
     }
     return $this->redis->expire($key, (int) $ttl);
 }
开发者ID:everlution,项目名称:redlock,代码行数:13,代码来源:PhpRedisAdapter.php

示例5: set

 /**
  * Set a value identified by $key and with an optional $ttl.
  *
  * @param string $key
  * @param mixed  $value
  * @param int    $ttl
  *
  * @return $this
  */
 public function set($key, $value, $ttl = 0)
 {
     $ttl = $this->fromDefaultTtl($ttl);
     if ($ttl >= 0) {
         if ($this->isAvailable()) {
             $this->redis->set($key, $this->storageDataStructure($value));
             if ($ttl > 0) {
                 $this->redis->expire($key, $ttl);
             }
         }
         $this->setChain($key, $value, $ttl);
     }
     return $this;
 }
开发者ID:nilportugues,项目名称:cache,代码行数:23,代码来源:AbstractAdapter.php

示例6: lockSession

 /**
  * @param string $sessionId
  */
 private function lockSession($sessionId)
 {
     $attempts = 1000000 / $this->spinLockWait * $this->lockMaxWait;
     $this->lockKey = $sessionId . '.lock';
     for ($i = 0; $i < $attempts; $i++) {
         $success = $this->redis->setnx($this->prefix . $this->lockKey, '1');
         if ($success) {
             $this->locked = true;
             $this->redis->expire($this->prefix . $this->lockKey, $this->lockMaxWait + 1);
             return true;
         }
         usleep($this->spinLockWait);
     }
     return false;
 }
开发者ID:vaidasif,项目名称:symfony-force,代码行数:18,代码来源:RedisSessionHandler.php

示例7: expire

 /**
  * @param string $key
  * @param int $ttl
  * @return bool
  */
 public function expire($key, $ttl)
 {
     $this->_useCnt++;
     return $this->_wrapBoolReturn(function () use($key, $ttl) {
         return parent::expire($key, $ttl);
     });
 }
开发者ID:telander,项目名称:waka,代码行数:12,代码来源:Wk_Redis.php

示例8: incrBy

 public function incrBy($chiave, $valore = 1, $scadenza = Cache::SCADENZA_DEFAULT)
 {
     $x = parent::incrBy($chiave, $valore);
     if ($scadenza) {
         parent::expire($chiave, $scadenza);
     }
     return $x;
 }
开发者ID:pizar,项目名称:gaia,代码行数:8,代码来源:Cache.php

示例9: appendValue

 /**
  * Appends data to an existing item on the Redis server.
  *
  * @param  string $key
  * @param  string $value
  * @param  int    $expiration
  * @return bool
  */
 protected function appendValue($key, $value, $expiration = 0)
 {
     if ($this->redis->exists($key)) {
         $this->redis->append($key, $value);
         return $this->redis->expire($key, $expiration);
     }
     return $this->redis->setex($key, $expiration, $value);
 }
开发者ID:snc,项目名称:SncRedisBundle,代码行数:16,代码来源:RedisProfilerStorage.php

示例10: 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);
         }
     }
 }
开发者ID:nickel715,项目名称:pinboard-archive,代码行数:9,代码来源:WaybackMachine.php

示例11: set

 /**
  * Set an item in the cache
  *
  * @param string $key
  * @param mixed $value
  * @param int|\DateInterval|\DateTime $validity Number of seconds this is valid for (if int)
  * @return void
  */
 function set($key, $value, $validity = null)
 {
     $this->connection->set($key, $value);
     if ($validity instanceof \DateInterval) {
         $validity = (new \DateTimeImmutable())->add($validity);
     }
     if ($validity instanceof \DateTimeInterface) {
         $this->connection->expireat($key, $validity->getTimestamp());
     } else {
         if (is_numeric($validity)) {
             $this->connection->expire($key, $validity);
         } else {
             if ($validity != null) {
                 throw new \UnexpectedValueException("Unexpected validity");
             }
         }
     }
 }
开发者ID:digitalcreations,项目名称:cache-phpredis,代码行数:26,代码来源:Cache.php

示例12: touch

 /**
  * Set the last modified time to the current time
  *
  * @return bool Success status
  */
 public function touch()
 {
     $data = $this->cache->get($this->name);
     if ($data !== false) {
         $return = $this->cache->set($this->name, $data);
         if ($this->options['expire']) {
             return $this->cache->expire($this->name, $this->ttl);
         }
         return $return;
     }
     return false;
 }
开发者ID:janeklb,项目名称:moodle,代码行数:17,代码来源:Redis.php

示例13: test4_set2

function test4_set2()
{
    $cache = new Redis();
    $cache->pconnect('127.0.0.1', 7001);
    $t1 = microtime(1);
    for ($i = 0; $i < 10000; $i++) {
        $cache->set('qwe' . $i, 'hello' . $i);
        $cache->expire('qwe' . $i, 1800);
    }
    $t2 = microtime(1);
    var_dump($t2 - $t1);
    echo "\n";
}
开发者ID:shendongming,项目名称:php-redis-cache,代码行数:13,代码来源:testRedisCache.php

示例14: testPersist

 public function testPersist()
 {
     $this->redis->set('x', 'y');
     $this->redis->expire('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->del('x');
     $this->assertTrue(FALSE === $this->redis->persist('x'));
     // false if the key doesn’t exist.
 }
开发者ID:Jerry-Shaw,项目名称:phpredis,代码行数:14,代码来源:RedisTest.php

示例15: write

 /**
  * Write data to the session.
  *
  * @param string  $id
  * @param mixed   $data
  * @return bool
  */
 public function write($id, $data)
 {
     // This might be the first set for this session key, so we have to check if it's already exists in redis
     if ($this->_id !== $id) {
         // Perform getset to check if session already exists in redis
         if ($this->_redis->getSet($this->_buildKey($id), $data) === false) {
             // session doesn't exists in redis, so we have to set expiration
             $this->_redis->expire($this->_buildKey($id), $this->_config['lifetime']);
         }
         // Backup id, so we'll know that expiration has already been set, we'll avoid to perform getset on the next write
         $this->_id = $id;
     } else {
         // This is not the first write in script execution, just update value
         $this->_redis->set($this->_buildKey($id), $data);
     }
     return true;
 }
开发者ID:gzweb,项目名称:Zebra-PHP-Framework,代码行数:24,代码来源:RedisSession.php


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