本文整理汇总了PHP中Predis\Client::incr方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::incr方法的具体用法?PHP Client::incr怎么用?PHP Client::incr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Predis\Client
的用法示例。
在下文中一共展示了Client::incr方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: persist
/**
* 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);
}
示例2: addBeaconMetricTotal
/**
* 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;
}
示例3: register
/**
* @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;
}
示例4: tweet
/**
* @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);
}
示例5: generateNewHashAndStoreIt
/**
* 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;
}
示例6: send
/**
* @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;
}
示例7: increase
/**
* 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;
}
示例8: generate
/**
* @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));
}
示例9: clear
/**
* {@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;
}
示例10: put
public function put($job)
{
$job['id'] = $this->redis->incr("job_id");
$this->redis->lpush("jobs", serialize($job));
return $job['id'];
}
示例11: incrementKey
public function incrementKey($key)
{
return $this->client->incr($key);
}
示例12: addBeaconMetricTotal
/**
* 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;
}
示例13: flushAll
public function flushAll($db, $table)
{
$key = implode(':', [$this->prefix, self::KEY_SCHEMA_VERSION, $db, $table]);
$key = md5($key);
$this->redis->incr($key);
}
示例14: increment
/**
* @param CertificationEvent $event
*/
public function increment(CertificationEvent $event)
{
$this->redisClient->incr('total');
$this->redisClient->incr($event->getCertification()->getContext()->getName());
$this->redisClient->bgsave();
}