You are here

public function ReliablePhpRedis::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/ReliablePhpRedis.php, line 37

Class

ReliablePhpRedis
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();
  $result = $this->client
    ->multi()
    ->hsetnx($this->availableItems, $record->qid, serialize($record))
    ->lLen($this->availableListKey)
    ->lpush($this->availableListKey, $record->qid)
    ->exec();
  $success = $result[0] && $result[2] > $result[1];
  return $success ? $record->qid : FALSE;
}