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


PHP ClientInterface::set方法代码示例

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


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

示例1: cacheSet

 /**
  * Set the cache for a token.
  *
  * @param $key
  * @param string $value
  * @param null $expiration
  */
 protected function cacheSet($key, $value, $expiration = null)
 {
     $this->client->set($key, $value);
     if (!empty($expiration)) {
         $this->ttl = $expiration;
     }
     $this->client->expire($key, $this->ttl);
 }
开发者ID:cultuurnet,项目名称:symfony-security-oauth-redis,代码行数:15,代码来源:TokenProviderCache.php

示例2: set

 /**
  * Sets a cache entry
  *
  * @param $key
  * @param $value
  * @return void
  */
 public function set($key, $value)
 {
     if ($this->ttl === null) {
         $this->client->set($key, $this->serializer->serialize($value));
     } else {
         $this->client->set($key, $this->serializer->serialize($value), 'ex', $this->ttl);
     }
 }
开发者ID:genkgo,项目名称:cache,代码行数:15,代码来源:PredisAdapter.php

示例3: write

 /**
  * Write value for a key into cache
  *
  * @param string $key Identifier for the data
  * @param mixed $value Data to be cached
  * @return bool True if the data was successfully cached, false on failure
  */
 public function write($key, $value)
 {
     $key = $this->_key($key);
     $value = is_int($value) ? (int) $value : serialize($value);
     if ($this->_config['duration'] === 0) {
         return (string) $this->client->set($key, $value) === 'OK';
     }
     return (string) $this->client->setex($key, $this->_config['duration'], $value) === 'OK';
 }
开发者ID:renan,项目名称:cakephp-predis,代码行数:16,代码来源:PredisEngine.php

示例4: doSave

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

示例5: getPosts

 /**
  * @return array
  */
 public function getPosts() : array
 {
     if ($this->redisClient !== null) {
         $posts = $this->redisClient->get('posts');
         if ($posts) {
             return json_decode($posts, true);
         }
     }
     $blog = $this->getBlogInfo();
     $posts = $this->thumblrClient->getBlogPosts($blog['name'], ['type' => 'text'])->posts;
     $posts = json_encode($posts, JSON_PRETTY_PRINT);
     if ($this->redisClient !== null) {
         $this->redisClient->set('posts', $posts);
         $this->redisClient->expireat('posts', time() + 3600);
     }
     return json_decode($posts, true);
 }
开发者ID:devigner,项目名称:devigner.io,代码行数:20,代码来源:TumblrModel.php

示例6: testCacheGet

 /**
  * @test
  */
 public function testCacheGet()
 {
     $token = $this->tokenProvider->getAccessTokenByToken('nnch734d00sl2jdk');
     $serializedToken = serialize($token);
     $key = 'tokenProvider/token/key:nnch734d00sl2jdk';
     $this->client->set($key, $serializedToken);
     $cachedToken = $this->tokenProviderCache->cacheGet($key);
     $this->assertEquals($serializedToken, $cachedToken);
 }
开发者ID:cultuurnet,项目名称:symfony-security-oauth-redis,代码行数:12,代码来源:TokenProviderCacheTest.php

示例7: set

 /**
  * @param string $key
  * @param mixed $value
  * @param int|null $ttl
  *
  * @throws \Exception
  *
  * @return mixed
  */
 public function set($key, $value, $ttl = null)
 {
     $key = $this->getKeyName($key);
     if ($ttl === null) {
         $result = $this->client->set($key, $value);
     } else {
         $result = $this->client->setex($key, $ttl, $value);
     }
     $this->addWriteAccessStats($key);
     if (!$result) {
         throw new \Exception('could not set redisKey: "' . $key . '" with value: "' . json_encode($value) . '"');
     }
     return $result;
 }
开发者ID:spryker,项目名称:Storage,代码行数:23,代码来源:Service.php

示例8: acquire

 /**
  * Acquire the lock.
  *
  * Returns true if we were able to acquire the lock, and if we weren't able
  * to acquire it in time, we return false.
  *
  * @return bool
  */
 public function acquire()
 {
     $attempts = 0;
     while (true) {
         $this->token = str_random(32);
         if ($this->redis->set($this->name, $this->token, 'NX', 'PX', $this->timeout)) {
             $this->state = $this->time();
             return true;
         }
         $attempts++;
         if ($attempts >= $this->attempts) {
             return false;
         }
         usleep(random_int($this->min, $this->max));
     }
 }
开发者ID:AltThree,项目名称:Locker,代码行数:24,代码来源:Lock.php

示例9: postRequestHandle

 /**
  * @param SessionInterface $session
  * @param Response $response
  */
 private function postRequestHandle(SessionInterface $session, Response $response)
 {
     if ($this->sessionIsPersistent($config = $this->manager->getSessionConfig())) {
         $id = $session->getId();
         $key = 'session:' . $id;
         $content = $session->all();
         unset($content['_token'], $content['flash']);
         $lastSeen = time();
         $content['last_seen'] = $lastSeen;
         $session->set('last_seen', $lastSeen);
         $value = Json::dump($content);
         $this->redis->watch($key);
         $this->redis->multi();
         $this->redis->set($key, $value);
         $this->redis->expire($key, $this->getSessionLifetimeInSeconds());
         $this->redis->exec();
         $cookie = new Cookie($this->key, $id, $this->getCookieExpirationDate(), $config['path'], $config['domain'], Arr::get($config, 'secure', false));
         $response->headers->setCookie($cookie);
     }
 }
开发者ID:spyc,项目名称:elearn-foundation,代码行数:24,代码来源:CommonSession.php

示例10: set

 /**
  * {@inheritDoc}
  */
 public function set($key, $value)
 {
     return $this->predis->set($key, $value);
 }
开发者ID:php-resque,项目名称:resque,代码行数:7,代码来源:PredisBridge.php

示例11: testStringLength

 /**
  * @group redis-strings
  */
 public function testStringLength()
 {
     $this->assertSame(0, $this->client->strlen('foo'));
     $this->client->set('foo', 'bar');
     $this->assertSame(3, $this->client->strlen('foo'));
 }
开发者ID:gmo,项目名称:cache,代码行数:9,代码来源:PredisTest.php

示例12: save

 /**
  * Save some data to the cache
  *
  * @param $key
  * @param $data
  * @param $timeout
  * @return mixed
  */
 public function save($key, $data, $timeout)
 {
     return $this->redisClient->set($key, $data, 'ex', $timeout);
 }
开发者ID:kabudu,项目名称:forecast-tools,代码行数:12,代码来源:RedisCacheHandler.php


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