本文整理匯總了PHP中Predis\Client::zadd方法的典型用法代碼示例。如果您正苦於以下問題:PHP Client::zadd方法的具體用法?PHP Client::zadd怎麽用?PHP Client::zadd使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Predis\Client
的用法示例。
在下文中一共展示了Client::zadd方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: add
/**
* {@inheritDoc}
*/
public function add($source, $type, $unique, array $data, \DateTime $timestamp = null)
{
$identifier = base64_encode(implode(':', [$source, $type, $unique]));
$timestamp = $timestamp ?: new \DateTime();
$this->redis->hset('aggregator:objects', $identifier, json_encode(['source' => $source, 'type' => $type, 'unique' => $unique, 'data' => $data, 'timestamp' => $timestamp->format('U')]));
$this->redis->zadd("aggregator:sources:{$source}", $timestamp->format('U'), $identifier);
}
示例2: later
/**
* {@inheritdoc}
*/
public function later($delay, $job, $data = '', string $queue = null)
{
$payload = $this->createPayload($job, $data);
$delay = $this->getSeconds($delay);
$this->redis->zadd($this->getQueue($queue) . ':delayed', $this->getTime() + $delay, $payload);
return Arr::get(json_decode($payload, true), 'id');
}
示例3: haveInRedis
/**
* Creates or modifies keys
*
* If $key already exists:
*
* - Strings: its value will be overwritten with $value
* - Other types: $value items will be appended to its value
*
* Examples:
*
* ``` php
* <?php
* // Strings: $value must be a scalar
* $I->haveInRedis('string', 'Obladi Oblada');
*
* // Lists: $value can be a scalar or an array
* $I->haveInRedis('list', ['riri', 'fifi', 'loulou']);
*
* // Sets: $value can be a scalar or an array
* $I->haveInRedis('set', ['riri', 'fifi', 'loulou']);
*
* // ZSets: $value must be an associative array with scores
* $I->haveInRedis('set', ['riri' => 1, 'fifi' => 2, 'loulou' => 3]);
*
* // Hashes: $value must be an associative array
* $I->haveInRedis('hash', ['obladi' => 'oblada']);
* ```
*
* @param string $type The type of the key
* @param string $key The key name
* @param mixed $value The value
*
* @throws ModuleException
*/
public function haveInRedis($type, $key, $value)
{
switch (strtolower($type)) {
case 'string':
if (!is_scalar($value)) {
throw new ModuleException($this, 'If second argument of haveInRedis() method is "string", ' . 'third argument must be a scalar');
}
$this->driver->set($key, $value);
break;
case 'list':
$this->driver->rpush($key, $value);
break;
case 'set':
$this->driver->sadd($key, $value);
break;
case 'zset':
if (!is_array($value)) {
throw new ModuleException($this, 'If second argument of haveInRedis() method is "zset", ' . 'third argument must be an (associative) array');
}
$this->driver->zadd($key, $value);
break;
case 'hash':
if (!is_array($value)) {
throw new ModuleException($this, 'If second argument of haveInRedis() method is "hash", ' . 'third argument must be an array');
}
$this->driver->hmset($key, $value);
break;
default:
throw new ModuleException($this, "Unknown type \"{$type}\" for key \"{$key}\". Allowed types are " . '"string", "list", "set", "zset", "hash"');
}
}
示例4: release
/**
* @inheritdoc
*/
public function release(array $message, $delay = 0)
{
if ($delay > 0) {
$this->redis->zadd($message['queue'] . ':delayed', [$message['body'] => time() + $delay]);
} else {
$this->redis->rpush($message['queue'], [$message['body']]);
}
}
示例5: addDataListToZSet
/**
*
* @param array $data
* e.g:
* [
* [score, member],
* [score1, member1],
* ...
* ]
* @param $key
* @param callable $scoreMemberHandle
* @return int|number
*/
protected function addDataListToZSet($key, array $data, callable $scoreMemberHandle)
{
if (!$data || !$key) {
return 0;
}
// $pip = $this->redis->pipeline();
// $pip = $this->redis->watch($key);
$this->redis->multi();
foreach ($data as $row) {
list($score, $member) = $scoreMemberHandle($row);
$this->redis->zadd($key, [(string) $member => $score]);
}
$result = $this->redis->exec();
return array_sum($result);
}
示例6: atomicPush
/**
* Push job to redis
*
* @param string $jobId
* @param string $class
* @param array $args
* @param string $queue
* @param bool $retry
* @param float|null $doAt
* @throws exception Exception
*/
private function atomicPush($jobId, $class, $args = [], $queue = self::QUEUE, $retry = true, $doAt = null)
{
if (array_values($args) !== $args) {
throw new Exception('Associative arrays in job args are not allowed');
}
if (!is_null($doAt) && !is_float($doAt) && is_string($doAt)) {
throw new Exception('at argument needs to be in a unix epoch format. Use microtime(true).');
}
$job = $this->serializer->serialize($jobId, $class, $args, $retry);
if ($doAt === null) {
$this->redis->sadd($this->name('queues'), $queue);
$this->redis->lpush($this->name('queue', $queue), $job);
} else {
$this->redis->zadd($this->name('schedule'), [$job => $doAt]);
}
}
示例7: zSetSave
private function zSetSave()
{
return $this->client->zadd($this->key_header, array($this->message->getJsonFormat() => strtotime($this->message->getCreateAt())));
}