/** * {@inheritdoc} */ public function read($sessionId) { if ($data = $this->redis->get($sessionId)) { return $data; } return ''; }
/** * {@inheritdoc} */ protected function doFetch($id) { $result = $this->client->get($id); if (null === $result) { return false; } return unserialize($result); }
/** * Read a key from the cache * * @param string $key Identifier for the data * @return mixed The cached data, or false if the data doesn't exist, has expired, or if there was an error fetching it */ public function read($key) { $key = $this->_key($key); $value = $this->client->get($key); if ($value === null) { return false; } return ctype_digit($value) ? (int) $value : unserialize($value); }
/** * @test */ public function testCacheSet() { $token = $this->tokenProvider->getAccessTokenByToken('nnch734d00sl2jdk'); $serializedToken = serialize($token); $key = 'tokenProvider/token/key:nnch734d00sl2jdk'; $this->tokenProviderCache->cacheSet($key, $serializedToken); $cachedToken = $this->client->get($key); $this->assertEquals($serializedToken, $cachedToken); }
/** * @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); }
/** * @param SessionInterface $session * @param Request $request */ private function preRequestHandle(SessionInterface $session, Request $request) { $id = $request->cookie($this->key); $key = 'session:' . $id; if (!Str::equals($key, $session->getId())) { $this->redis->del($key); return; } $value = $this->redis->get('session:' . $key); $content = Json::parse($value); if ($content['last_seen'] > $session->get('last_seen')) { foreach ($content as $key => $value) { if (!Str::startsWith($key, ['_', 'login_'])) { $session->set($key, $value); } } } }
/** * @param string $key * * @return mixed */ public function get($key) { $key = $this->getKeyName($key); $value = $this->client->get($key); $this->addReadAccessStats($key); $result = json_decode($value, true); if (json_last_error() === \JSON_ERROR_SYNTAX) { return $value; } return $result; }
/** * @group redis-strings */ public function testSetRange() { $this->assertSame(9, $this->client->setrange('foo', 4, 'World')); $this->assertSame("World", $this->client->get('foo')); $this->client->set('foo', 'Hello World'); $this->assertSame(14, $this->client->setrange('foo', 6, 'Universe')); $this->assertSame('Hello Universe', $this->client->get('foo')); $this->client->set('foo', 'bar'); $this->assertSame(9, $this->client->setrange('foo', 6, 'baz')); $this->assertSame("barbaz", $this->client->get('foo')); }
/** * {@inheritDoc} */ public function get($key) { return $this->predis->get($key); }
/** * Get the cached token for a key. * * @param $key * @return string */ protected function cacheGet($key) { $cachedToken = $this->client->get($key); return $cachedToken; }
/** * Gets a cache entry * returning null if not in cache * * @param $key * @return null|mixed */ public function get($key) { return $this->serializer->deserialize($this->client->get($key)); }
/** * Fetch some data from the cache with this key * * @param $key * @return string */ public function fetch($key) { return $this->redisClient->get($key); }