本文整理汇总了PHP中Predis\Client::rpush方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::rpush方法的具体用法?PHP Client::rpush怎么用?PHP Client::rpush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Predis\Client
的用法示例。
在下文中一共展示了Client::rpush方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: publish
/**
* @param string $queue Name of the queue to receive the job
* @param string $command FQCN for Command class to be executed by the job
* @param array $options Options for the Command class instance
*/
public function publish($queue, $command, array $options = [])
{
if (!is_subclass_of($command, CommandInterface::class)) {
throw new \RuntimeException('Class does not implement CommandInterface: ' . $command);
}
$job = json_encode(['command' => $command, 'options' => $options]);
$this->client->rpush($queue, $job);
}
示例2: append
public function append(EventStream $events)
{
foreach ($events as $event) {
$data = $this->serializer->serialize($event, 'json');
$event = $this->serializer->serialize(['type' => get_class($event), 'created_on' => (new DateTimeImmutable('now', new DateTimeZone('UTC')))->getTimestamp(), 'data' => $data], 'json');
$this->predis->rpush('events:' . $events->aggregateId(), $event);
$this->predis->rpush('published_events', $event);
}
}
示例3: put
/**
* @param string $key
* @param string $value
* @param QueuePriority $priority
* @return bool
*/
public function put($key, $value, QueuePriority $priority = null)
{
if (!$priority) {
$priority = QueuePriority::PRIORITY_NORMAL;
}
if ($this->checkConnection()) {
return $this->predis->rpush(self::QUEUE_PREFIX . ':' . $priority . ':' . $key, $value);
}
return false;
}
示例4: initializeRedis
/**
* Make sure, the Redis keys exist.
*
* @return void
*/
private function initializeRedis()
{
if ($this->initialized) {
return;
}
$this->hash = substr(sha1(serialize($this->items)), 0, 8);
$positionKey = $this->getKeyForCurrentPosition();
$existing = !$this->redis->setnx($positionKey, count($this->items) - 1);
if (!$existing && count($this->items)) {
$listKey = $this->getKeyForItemList();
$this->itemCount = $this->redis->rpush($listKey, $this->items);
}
$this->initialized = true;
}
示例5: listen
/**
* Start the worker and wait for requests
*/
public function listen()
{
$context = new \ZMQContext();
$server = new \ZMQSocket($context, \ZMQ::SOCKET_PULL);
$server->bind('tcp://127.0.0.1:' . ($this->defaultPort + $this->client->getId() - 1));
$this->logger->info('Client worker ' . $this->client . ' is ready');
while (true) {
$request = $server->recv();
$this->logger->debug('Client worker ' . $this->client . ' receiving request : ' . $request);
// Check if the input is valid, ignore if wrong
$request = json_decode($request, true);
if (!$this->isValidInput($request)) {
$this->logger->error('Client worker ' . $this->client . ' received an invalid input');
continue;
}
try {
// Call the right method in the client and push to redis the result
$result = call_user_func_array(array($this->client, $request['command']), $request['parameters']);
} catch (ClientNotReadyException $e) {
$this->logger->warning('Client worker ' . $this->client . ' received a request (#' . $request['invokeId'] . ') whereas the client is not ready. This is normal in case of client reconnection process. Ignoring.');
continue;
}
$key = $this->key . '.client.commands.' . $request['invokeId'];
$this->redis->rpush($key, serialize($result));
$this->redis->expire($key, $this->expire);
}
}
示例6: 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"');
}
}
示例7: 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']]);
}
}
示例8: addTask
/**
* @param Task $task
* @return null
*/
function addTask(Task $task)
{
$serialized = serialize($task);
$existingStatus = $this->getStatus($task);
if ($existingStatus) {
//TODO - what should happen here?
return null;
}
$taskKey = $task->getKey();
$this->redisClient->set($taskKey, $serialized);
$this->redisClient->rpush($this->announceListKey, $taskKey);
$this->setStatus($taskKey, TaskQueue::STATE_INITIAL);
}
示例9: addTask
/**
* @param Task $task
* @return null
*/
public function addTask(Task $task)
{
$taskKey = $task->getKey();
$taskSpecificKey = $this->taskListKey . $taskKey;
$serialized = serialize($task);
$existingStatus = $this->getStatus($task);
if ($existingStatus) {
//TODO - what should happen here?
return $taskSpecificKey;
}
$this->redisClient->set($taskSpecificKey, $serialized, 'EX', self::TASK_TTL);
$this->redisClient->rpush($this->announceListKey, $taskKey);
$this->setStatus($task, TaskQueue::STATE_INITIAL);
return true;
}
示例10: put
/**
* @param string $queueName
* @param mixed $workload
*/
public function put($queueName, $workload)
{
$this->predis->rpush($queueName, serialize($workload));
}
示例11: write
/**
* @param array $record
*/
protected function write(array $record)
{
$this->redisClient->rpush($this->redisKey, sprintf('%s|%s', $record['level'], $record['message']));
}
示例12: writeCommandReply
/**
* @param string $commandIdentifier
* @param mixed $reply
*/
public function writeCommandReply($commandIdentifier, $reply)
{
$this->client->rpush(sprintf(self::COMMAND_RESPONSE_KEY, $commandIdentifier), [$reply]);
$this->client->expire(sprintf(self::COMMAND_RESPONSE_KEY, $commandIdentifier), $this->timeout);
}
示例13: setList
/**
* 设置列表数据
* @param string $key
* @param array $elements
* @return int
*/
public function setList($key, $elements)
{
// list:magazine:100:images 12 13 14
return $this->redis->rpush($key, (array) $elements);
}
示例14: recordGauge
public function recordGauge($name, $value, $measureTime = null)
{
$counter = new \Stats\Gauge($name, $value, $this->sourceName, $measureTime);
$serialized = serialize($counter);
$this->redisClient->rpush($this->getGaugeKey(), [$serialized]);
}
示例15: sendMessage
public function sendMessage($messageBody, $queueId = null)
{
$queueId = $this->normaliseQueueId($queueId);
$this->predis->rpush($queueId, [$messageBody]);
}