/** * 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); }
/** * Add beacon total nb given the key entry. * * @param string $entryKey Key entry * * @return $this Self Object */ private function addBeaconMetricTotal($entryKey) { $this->doRedisQuery(function () use($entryKey) { $this->redis->incr($entryKey . '_total'); }); return $this; }
/** * @param $username * @param $password * * @throws UsernameExistsException * * @return string */ public function register($username, $password) { if ($this->checkIfUsernameExists($username)) { throw new UsernameExistsException(UsernameExistsException::MESSAGE); } $userId = $this->redisClient->incr("global:nextUserId"); $this->redisClient->set("username:{$username}:id", $userId); $this->redisClient->set("uid:{$userId}:username", $username); $this->redisClient->set("uid:{$userId}:password", $password); $authSecret = $this->getRand(); $this->redisClient->set("uid:{$userId}:auth", $authSecret); $this->redisClient->set("auth:{$authSecret}", $userId); $this->redisClient->sadd("global:users", [$userId]); $this->session->set('userId', $userId); $this->session->set('username', $username); return $authSecret; }
/** * @param string $status */ public function tweet($status) { $postId = $this->redisClient->incr("global:nextPostId"); $userId = $this->session->get('userId'); $post = $userId . "|" . (new \DateTime())->format('d/m/y') . "|" . $status; $this->redisClient->set("post:{$postId}", $post); $followers = $this->redisClient->smembers("uid:" . $userId . ":followers"); if ($followers === false) { $followers = []; } $followers[] = $userId; foreach ($followers as $fid) { $this->redisClient->lpush("uid:{$fid}:posts", [$postId]); } $this->redisClient->lpush("global:timeline", [$postId]); $this->redisClient->ltrim("global:timeline", 0, 1000); }
/** * Generates a new hash for the route and stores 2 keys (sha1 and hash) in Redis * @param string $sha1 * @param string $route * @return mixed|string */ private function generateNewHashAndStoreIt($sha1, $route) { $id = $this->redis->incr($this->getUniqueKey()); $hash = $this->encode($id); $result = json_encode(array('hash' => $hash, 'route' => $route)); $this->redis->set($this->getSha1Key() . ":{$sha1}", $result); $this->redis->set($this->getHashKey() . ":{$hash}", $sha1); return $result; }
/** * @param string $commandName * @param array $parameters * @param int|string|null $invokeId * * @return int|string */ protected function send($commandName, array $parameters = array(), $invokeId = null) { if (null == $invokeId) { $invokeId = $this->redis->incr($this->getKey('invokeId')); } $nextAvailableTime = (double) ConfigurationLoader::get('client.request.overload.available'); $this->lastCall = microtime(true) + $nextAvailableTime; $this->con->send(json_encode(['invokeId' => $invokeId, 'command' => $commandName, 'parameters' => $parameters]), \ZMQ::MODE_DONTWAIT); return $invokeId; }
/** * Increase the cache item. * * @see http://redis.io/commands/incr * @see http://redis.io/commands/incrby * * @param string $key The cache key * @param int $increment Increment value * * @return mixed */ public function increase($key, $increment = 1) { $increment = abs((int) $increment); if ($increment <= 1) { $this->client->incr($key); } else { $this->client->incrby($key, $increment); } return $this; }
/** * @return IdValue */ public function generate() { $timestamp = $this->generateTimestamp(); $sequence = 0; if (!is_null($this->lastTimestamp) && $timestamp->equals($this->lastTimestamp)) { // Get $sequence = $this->redis->incr(self::REDIS_SEQUENCE_KEY) & $this->config->getSequenceMask(); if ($sequence === 0) { usleep(1000); $timestamp = $this->generateTimestamp(); } } else { // Reset sequence if timestamp is different from last one. $sequence = 0; $this->redis->set(self::REDIS_SEQUENCE_KEY, $sequence); } // Update lastTimestamp $this->lastTimestamp = $timestamp; return new IdValue($timestamp, $this->regionId, $this->serverId, $sequence, $this->calculate($timestamp, $this->regionId, $this->serverId, $sequence)); }
/** * {@inheritdoc} */ public function clear($key = null) { if (is_null($key)) { $this->redis->flushdb(); return true; } $keyString = $this->makeKeyString($key, true); $keyReal = $this->makeKeyString($key); $this->redis->incr($keyString); // increment index for children items $this->redis->del($keyReal); // remove direct item. $this->keyCache = array(); return true; }
public function put($job) { $job['id'] = $this->redis->incr("job_id"); $this->redis->lpush("jobs", serialize($job)); return $job['id']; }
public function incrementKey($key) { return $this->client->incr($key); }
/** * Add beacon total nb given the key entry * * @param string $entryKey Key entry * * @return $this Self Object */ private function addBeaconMetricTotal($entryKey) { $this->redis->incr($entryKey . '_total'); return $this; }
public function flushAll($db, $table) { $key = implode(':', [$this->prefix, self::KEY_SCHEMA_VERSION, $db, $table]); $key = md5($key); $this->redis->incr($key); }
/** * @param CertificationEvent $event */ public function increment(CertificationEvent $event) { $this->redisClient->incr('total'); $this->redisClient->incr($event->getCertification()->getContext()->getName()); $this->redisClient->bgsave(); }