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


PHP Client::setex方法代码示例

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


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

示例1: set

 /**
  * @inheritdoc
  */
 public function set($key, $value, $ttl = 0)
 {
     if ($ttl > 0) {
         return $this->predis->setex($key, $ttl, $value);
     }
     return $this->predis->set($key, $value);
 }
开发者ID:savritsky,项目名称:cache,代码行数:10,代码来源:PredisDriver.php

示例2: write

 /**
  * {@inheritDoc}
  */
 public function write($sessionId, $data)
 {
     if (0 < $this->ttl) {
         $this->redis->setex($this->getRedisKey($sessionId), $this->ttl, $data);
     } else {
         $this->redis->set($this->getRedisKey($sessionId), $data);
     }
 }
开发者ID:ronnylt,项目名称:SncRedisBundle,代码行数:11,代码来源:RedisSessionHandler.php

示例3: createUserToken

 /**
  * @param int $userId
  *
  * @return string
  */
 public function createUserToken($userId)
 {
     $generator = new SecureRandom();
     $rand = $generator->nextBytes(12);
     $wsseToken = sha1($rand);
     $this->redis->setex(self::PREFIX . ':' . $userId, $this->ttl, $wsseToken);
     return $wsseToken;
 }
开发者ID:bzis,项目名称:zomba,代码行数:13,代码来源:WsseTokenManager.php

示例4: write

 /**
  * Save values for a set of keys to cache
  *
  * @param  array $keys list of values to save
  * @param  int   $expire expiration time
  *
  * @return boolean true on success, false on failure
  */
 protected function write(array $keys, $expire = 1)
 {
     foreach ($keys as $k => $v) {
         $k = sha1($k);
         $this->redis->setex($k, $expire, $v);
     }
     return true;
 }
开发者ID:noikiy,项目名称:Laravel.Smarty,代码行数:16,代码来源:Redis.php

示例5: doSave

 /**
  * {@inheritdoc}
  */
 protected function doSave($id, $data, $lifeTime = 0)
 {
     if ($lifeTime > 0) {
         $response = $this->client->setex($id, $lifeTime, $data);
     } else {
         $response = $this->client->set($id, $data);
     }
     return $response === true || $response == 'OK';
 }
开发者ID:neteasy-work,项目名称:hkgbf_crm,代码行数:12,代码来源:PredisCache.php

示例6: doSave

 /**
  * {@inheritdoc}
  */
 protected function doSave($id, $data, $lifeTime = false)
 {
     if (0 < $lifeTime) {
         $result = $this->redis->setex($id, (int) $lifeTime, serialize($data));
     } else {
         $result = $this->redis->set($id, serialize($data));
     }
     return (bool) $result;
 }
开发者ID:slaparra,项目名称:voting-details,代码行数:12,代码来源:RedisCache.php

示例7: save

 /**
  * {@inheritdoc}
  */
 public function save($id, $data, $lifeTime = 0)
 {
     if ($lifeTime > 0) {
         $response = $this->client->setex($this->prefix . $id, $lifeTime, $data);
     } else {
         $response = $this->client->set($this->prefix . $id, $data);
     }
     return $response === true || $response == 'OK';
 }
开发者ID:rsrodrig,项目名称:MeetMeSoftware,代码行数:12,代码来源:PredisDriver.php

示例8: set

 /**
  * Set a value against a key in the cache.
  *
  * @param string   $key     The key to store against
  * @param string   $value   A json_encoded value
  * @param int|null $expires Optional expiry time in seconds from now
  */
 public function set($key, $value = null, $expires = null)
 {
     if ($value === null) {
         return $this->clear($key);
     }
     if ($expires === null) {
         return $this->client->set($key, $value);
     }
     return $this->client->setex($key, $expires, $value);
 }
开发者ID:molovo,项目名称:amnesia,代码行数:17,代码来源:Predis.php

示例9: persist

 /**
  * Persist an error.
  * @param Error $error
  * @param Handler $handler
  * @return mixed
  */
 public function persist(Error $error, Handler $handler)
 {
     $errorKey = $this->generateRedisKey($error);
     $json = $error->toJson();
     if (is_int($this->ttl)) {
         $this->predisClient->setex($errorKey, $this->ttl, $json);
     } else {
         $this->predisClient->set($errorKey, $json);
     }
     $countKey = $this->generateRedisKey($error, 'count');
     $this->predisClient->incr($countKey);
 }
开发者ID:tomwright,项目名称:oopz,代码行数:18,代码来源:Redis.php

示例10: save

 /**
  * {@inheritdoc}
  */
 public function save($id, $data, $lifeTime = 0)
 {
     $id = $this->_getNamespacedId($id);
     $data = serialize($data);
     if ($this->_supportsSetExpire && 0 < $lifeTime) {
         $result = $this->_redis->setex($id, (int) $lifeTime, $data);
     } else {
         $result = $this->_redis->set($id, $data);
         if ($result && 0 < $lifeTime) {
             $result = $this->_redis->expire($id, (int) $lifeTime);
         }
     }
     return (bool) $result;
 }
开发者ID:realestateconz,项目名称:SncRedisBundle,代码行数:17,代码来源:RedisCache.php

示例11: validateDigest

 /**
  * @param string $digest
  * @param string $nonce
  * @param string $created
  * @param string $secret
  *
  * @return bool
  * @throws \Symfony\Component\Security\Core\Exception\NonceExpiredException
  */
 protected function validateDigest($digest, $nonce, $created, $secret)
 {
     /*
      * закомментили 7.01.2014 из-за проблемы возможного расхождения с клиентским временем
      *
     // Check created time is not in the future
     if (strtotime($created) > time()) {
         return false;
     }
     
     // Expire timestamp after 5 minutes
     if (time() - strtotime($created) > self::TTL) {
         return false;
     }
     */
     // Validate nonce is unique within 5 minutes
     if ($this->redis->exists(self::PREFIX . ':' . $nonce)) {
         if (null !== $this->logger) {
             $this->logger->debug(sprintf('Previously used nonce detected: %s', base64_decode($nonce)));
         }
         throw new NonceExpiredException('Previously used nonce detected');
     }
     $this->redis->setex(self::PREFIX . ':' . $nonce, self::TTL, time());
     // Validate Secret
     $expected = base64_encode(sha1(base64_decode($nonce) . $created . $secret, true));
     if (null !== $this->logger) {
         $this->logger->debug(sprintf('[+] %s, [=] %s (created: %s, nonce: %s, secret: %s)', $digest, $expected, $created, base64_decode($nonce), $secret));
     }
     return $digest === $expected;
 }
开发者ID:bzis,项目名称:zomba,代码行数:39,代码来源:WsseProvider.php

示例12: index

 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     //$a = new ArticleRepository(new \App\Article);
     //var_dump($a->getLatestArticles());exit();
     // 一页多少文章
     $pageNum = 10;
     $userInfo = \Auth::user();
     $data = array();
     $data['articles'] = Article::latest()->published()->get();
     $data['userInfo'] = $userInfo;
     $dataArticles = array();
     $curPage = isset($_REQUEST['page']) ? $_REQUEST['page'] : 1;
     $cacheKey = 'laravel:articles:index:page:' . $curPage;
     $redis = new \Predis\Client(array('host' => '127.0.0.1', 'port' => 6379));
     $dataArticles = $redis->get($cacheKey);
     if (!$dataArticles) {
         //$dataArticles = \App\Article::latest()->take($pageNum)->with('content')->get()->toArray();
         $dataArticles = App\Article::latest()->with('content')->paginate($pageNum)->toArray();
         //var_dump($dataArticles);exit();
         $redis->setex($cacheKey, 3600 * 12, serialize($dataArticles));
     } else {
         $dataArticles = unserialize($dataArticles);
     }
     $data['articles'] = $dataArticles;
     //var_dump($data);exit();
     // $articleArr[0]['relations']['content']['content']
     return view('articles.index')->with('data', $data);
 }
开发者ID:suhanyujie,项目名称:digitalOceanVps,代码行数:33,代码来源:ArticlesController.php

示例13: 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

示例14: write

 /**
  * @param string $sessionId
  * @param string $sessionData
  *
  * @return bool
  */
 public function write($sessionId, $sessionData)
 {
     $key = $this->keyPrefix . $sessionId;
     if (strlen($sessionData) < 1) {
         return true;
     }
     $startTime = microtime(true);
     $result = $this->connection->setex($key, $this->lifetime, json_encode($sessionData));
     $this->newRelicApi->addCustomMetric(self::METRIC_SESSION_WRITE_TIME, microtime(true) - $startTime);
     return $result ? true : false;
 }
开发者ID:spryker,项目名称:Session,代码行数:17,代码来源:SessionHandlerRedis.php

示例15: storeAssociation

 /**
  * Store association until its expiration time in Redis server. 
  * Overwrites any existing association with same server_url and 
  * handle. Handles list of associations for every server. 
  */
 function storeAssociation($server_url, $association)
 {
     // create Redis keys for association itself
     // and list of associations for this server
     $associationKey = $this->associationKey($server_url, $association->handle);
     $serverKey = $this->associationServerKey($server_url);
     // save association to server's associations' keys list
     $this->redis->lpush($serverKey, $associationKey);
     // Will touch the association list expiration, to avoid filling up
     $newExpiration = $association->issued + $association->lifetime;
     $expirationKey = $serverKey . '_expires_at';
     $expiration = $this->redis->get($expirationKey);
     if (!$expiration || $newExpiration > $expiration) {
         $this->redis->set($expirationKey, $newExpiration);
         $this->redis->expireat($serverKey, $newExpiration);
         $this->redis->expireat($expirationKey, $newExpiration);
     }
     // save association itself, will automatically expire
     $this->redis->setex($associationKey, $newExpiration - time(), serialize($association));
 }
开发者ID:Stony-Brook-University,项目名称:doitsbu,代码行数:25,代码来源:PredisStore.php


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