/** * {@inheritdoc} */ public function read($sessionId) { if ($dataSet = $this->client->get("wandu.http.sess.{$sessionId}")) { return unserialize($dataSet); } return []; }
/** * @param $username * * @return bool */ private function checkIfUsernameExists($username) { if ($this->redisClient->get("username:{$username}:id")) { return true; } return false; }
/** * {@inheritdoc} */ public function read($sessionId) { if ($dataSet = $this->client->get("wandu.http.sess.{$sessionId}")) { return $dataSet; } return ''; }
/** * {@inheritdoc} */ public function load() { $contents = $this->client->get($this->key); if ($contents) { $this->setFromStorage($contents); } }
/** * {@inheritdoc} */ protected function doFetch($id) { $result = $this->client->get($id); if (null === $result) { return false; } return unserialize($result); }
/** * @param $key * @return Password|null */ public function get($key) { $password = null; if ($passwordData = $this->client->get($key)) { $password = $this->getPasswordFromJson($passwordData); } return $password; }
/** * Get a variable * * @param string $key * @param mixed $default * @return mixed */ public function get($key, $default = null) { if ($this->client->exists($this->namespace . $key)) { return $this->client->get($this->namespace . $key); } else { return $default; } }
/** * {@inheritdoc} */ public function fetch($id) { $result = $this->client->get($this->prefix . $id); if (null === $result) { return false; } return $result; }
/** * @param string $sessionId * * @return string|null */ public function read($sessionId) { $key = $this->keyPrefix . $sessionId; $startTime = microtime(true); $result = $this->connection->get($key); $this->newRelicApi->addCustomMetric(self::METRIC_SESSION_READ_TIME, microtime(true) - $startTime); return $result ? json_decode($result, true) : ''; }
/** * @return void */ private function checkReadFromStorage() { try { $this->client->get(self::KEY_HEARTBEAT); } catch (\Exception $e) { $this->addDysfunction(self::HEALTH_MESSAGE_UNABLE_TO_READ_FROM_STORAGE); $this->addDysfunction($e->getMessage()); } }
/** * @param $jobId * * @return AbstractJob */ public function find($jobId) { $data = $this->redis->get($this->namespace . $jobId); $data = json_decode($data, true); $jobClass = $data[AbstractJob::P_JOB_CLASS]; /** @var AbstractJob $job */ $job = new $jobClass($data); return $job; }
/** * {@inheritdoc} */ public function getUpdatedAt() { if ($this->client->exists('migraine:date')) { $date = new \DateTime(); $date->setTimestamp(intval($this->client->get('migraine:date'))); return $date; } return null; }
/** * @param string $key * @return \SplitIO\Component\Cache\Item */ public function getItem($key) { $item = new Item($key); $redisItem = $this->client->get($key); if ($redisItem !== null) { $item->set($redisItem); } return $item; }
/** * {@inheritDoc} */ public function isCached($providerName, $query) { if (!$this->redis->exists($key = $this->getKey($providerName, $query))) { return false; } $cached = new BatchGeocoded(); $cached->fromArray($this->deserialize($this->redis->get($key))); return $cached; }
/** * @param Request $request * * @return \Symfony\Component\HttpFoundation\Response */ public function indexAction(Request $request) { $certificationCounter = []; foreach ($this->certificationManager->getCertifications() as $cn => $label) { $certificationCounter[$cn] = ['metrics' => (int) $this->redisClient->get($cn), 'label' => $label, 'icon' => $this->certificationManager->getContext($cn)->getIcons()]; } $response = $this->engine->renderResponse('@CertificationyWeb/Site/homepage.html.twig', ['count_members' => (int) $this->userRepository->countMembers(), 'certification_done' => (int) $this->redisClient->get('total'), 'certification_counters' => $certificationCounter]); return $response; }
public function getCurrentOrderAction(Application $app) { // Pause the execution until the display is updated while (true === json_decode($this->client->get(BogoBogoSorter::DISPLAYED_KEY))) { usleep(500); } $this->client->set(BogoBogoSorter::DISPLAYED_KEY, json_encode(true)); return $app->json(json_decode($this->client->get(BogoBogoSorter::DATA_KEY), true)); }
/** * @param $queueName * @return QueueItemInterface */ public function popItem($queueName) { $this->getKeys($queueName, true); $key = array_pop($this->keys); $itemRaw = $this->redis->get($key); $item = unserialize($itemRaw); $this->redis->del($key); return $item; }
/** * @param string $providerPrefix * @param string $uri * @param string $query * * @return bool|mixed */ public function get($providerPrefix, $uri, $query) { $hash = $this->getHash($providerPrefix, $uri, $query); $data = $this->client->get($hash); if (!empty($data)) { return $data; } return false; }
/** * {@inheritDoc} */ public function getValue($key, $namespace = KeyValue::DEFAULT_NAMESPACE) { $effectiveKey = $this->buildKey($key, $namespace); $value = $this->redisClient->get($effectiveKey); if (!$value) { throw new KeyNotFoundException($key, $namespace); } return unserialize($value); }
/** * Read values for a set of keys from cache * * @param array $keys list of keys to fetch * * @return array list of values with the given keys used as indexes * @return boolean true on success, false on failure */ protected function read(array $keys) { $_keys = $lookup = []; list($_keys, $lookup) = $this->eachKeys($keys, $_keys, $lookup); $_res = []; foreach ($_keys as $key) { $_res[$lookup[$key]] = $this->redis->get($key); } return $_res; }
/** * @return array */ public function showAllPosts() { $key = "global:timeline"; $posts = $this->redisClient->lrange($key, 0, 10); $postData = []; foreach ($posts as $post) { $postData[] = $this->redisClient->get("post:{$post}"); } return $postData; }
/** * @inheritdoc */ public function recheck($event) { $value = $this->client->get($event); if (!$value) { return; } foreach ($this->listeners[$event] ?? [] as $listener) { $listener($value); } $this->client->del([$event]); }
public function logout() { $userId = $this->session->get('userId'); $newAuthSecret = $this->getRand(); $oldAuthSecret = $this->redisClient->get("uid:{$userId}:auth"); $this->redisClient->set("uid:{$userId}:auth", $newAuthSecret); $this->redisClient->set("auth:{$newAuthSecret}", $userId); $this->redisClient->del("auth:{$oldAuthSecret}"); $this->session->set('userId', null); $this->session->set('username', null); }
/** * @see ResourceCache::getResourceForEntity */ public function getResourceForEntity(ResourceEntityInterface $entity) { $resource = NULL; if ($this->hasResourceForEntity($entity)) { $key = $this->getKeyFromEntity($entity); $resource = unserialize($this->redis->get($key)); } else { $resource = $this->createResource($entity); } return $resource; }
/** * @inheritdoc */ public function getAvailability(\string $id) : \bool { $key = sprintf(self::QUANTITY_KEY, $id); if (!$this->predis->exists($key)) { $value = $this->repository->getAvailability($id); $this->saveAvailability($id, $value); } else { $value = (int) $this->predis->get($key); } return $value; }
/** * @param $key * @return string * @throws MissingException * @throws UnavailableException */ public function get($key) { try { $encrypted = $this->client->get($key); if (empty($encrypted)) { throw new MissingException("No token found for {$key}"); } // decrypt to token after retrieval return $this->encryption->decrypt($encrypted); } catch (ServerException $ex) { throw new UnavailableException($ex->getMessage()); } }
/** * Fetches a persisted error. * @param Error $error * @return null|Error */ public function getPersisted(Error $error) { $result = null; $key = $this->generateRedisKey($error); $redisVal = $this->predisClient->get($key); if (is_string($redisVal) && strlen($redisVal) > 0) { $data = json_decode($redisVal); if (is_object($data)) { $result = new Error($data->type, $data->errNo, $data->errStr, $data->file, $data->line, $data->trace); } } return $result; }
/** * Get cache value * @param CacheKey $key * @return mixed */ public function get(CacheKey $key) { $value = $this->redis->get($this->getKey($key)); $unserialized = @unserialize($value); if ($unserialized !== false) { $value = $unserialized; } else { if ($value === null) { $value = false; } } return $value; }
/** * @param $username * @param $password * * @throws WrongUsernameOrPasswordException * * @return string */ public function login($username, $password) { $userId = $this->redisClient->get("username:{$username}:id"); if (!$userId) { throw new WrongUsernameOrPasswordException(WrongUsernameOrPasswordException::MESSAGE); } $realPassword = $this->redisClient->get("uid:{$userId}:password"); if ($realPassword != $password) { throw new WrongUsernameOrPasswordException(WrongUsernameOrPasswordException::MESSAGE); } $this->session->set('userId', $userId); $this->session->set('username', $username); return $this->redisClient->get("uid:{$userId}:auth"); }
/** * 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); }