本文整理汇总了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);
}
示例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);
}
}
示例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';
}
示例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';
}
示例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);
}
示例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);
}
示例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;
}
示例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));
}
}
示例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);
}
}
示例10: set
/**
* {@inheritDoc}
*/
public function set($key, $value)
{
return $this->predis->set($key, $value);
}
示例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'));
}
示例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);
}