You are here

public function PhpRedis::createItem in Redis 8

Adds a queue item and store it directly to the queue.

Parameters

$data: Arbitrary data to be associated with the new task in the queue.

Return value

A unique ID if the item was successfully created and was (best effort) added to the queue, otherwise FALSE. We don't guarantee the item was committed to disk etc, but as far as we know, the item is now in the queue.

Overrides QueueInterface::createItem

File

src/Queue/PhpRedis.php, line 37

Class

PhpRedis
Redis queue implementation using PhpRedis extension backend.

Namespace

Drupal\redis\Queue

Code

public function createItem($data) {
  $record = new \stdClass();
  $record->data = $data;
  $record->qid = $this
    ->incrementId();

  // We cannot rely on REQUEST_TIME because many items might be created
  // by a single request which takes longer than 1 second.
  $record->timestamp = time();
  if (!$this->client
    ->hsetnx($this->availableItems, $record->qid, serialize($record))) {
    return FALSE;
  }
  $start_len = $this->client
    ->lLen($this->availableListKey);
  if ($start_len < $this->client
    ->lpush($this->availableListKey, $record->qid)) {
    return $record->qid;
  }
  return FALSE;
}