You are here

abstract class Redis_Queue_Base in Redis 7.2

Same name and namespace in other branches
  1. 7.3 lib/Redis/Queue/Base.php \Redis_Queue_Base

Redis allows implementing reliable queues, here is the spec:

  • For each queue, you have 4 different HASH:
  • One for queued items queue:NAME:queued
  • One for claimed items being processed: queue:NAME:claimed
  • One for claimed items leave time: queue:NAME:leave Items from this one will be arbitrarily fetched at cron time and released when leave is outdated.
  • One containing the item values and other valuable stateful information: queue:NAME:data ;
  • For example, current job maximum identifier (auto increment emulation) will be stored in the "sequence" HASH key
  • All other keys within the HASH will be the items themselves, keys for those will always be numeric
  • Each time a queue will be emptied, even during a pragmatic process, it will be automatically deleted, reseting the sequence counter to the 0 value each time

You will find the driver specific implementation in the Redis_Queue_* classes as they may differ in how the API handles transaction, pipelining and return values.

Hierarchy

Expanded class hierarchy of Redis_Queue_Base

File

lib/Redis/Queue/Base.php, line 37

View source
abstract class Redis_Queue_Base extends Redis_AbstractBackend implements DrupalReliableQueueInterface {

  /**
   * Key prefix for queue data.
   */
  const QUEUE_KEY_PREFIX = 'queue';

  /**
   * Data HASH sequence key name.
   */
  const QUEUE_HKEY_SEQ = 'seq';

  /**
   * Queue name
   *
   * @var string
   */
  protected $name;

  /**
   * Get data HASH key
   *
   * Key will already be prefixed
   *
   * @return string
   */
  public function getKeyForData() {
    return $this
      ->getKey(self::QUEUE_KEY_PREFIX, $this->name, 'data');
  }

  /**
   * Get queued items LIST key
   *
   * Key will already be prefixed
   *
   * @return string
   */
  public function getKeyForQueue() {
    return $this
      ->getKey(self::QUEUE_KEY_PREFIX, $this->name, 'queued');
  }

  /**
   * Get claimed LIST key
   *
   * Key will already be prefixed
   *
   * @return string
   */
  public function getKeyForClaimed() {
    return $this
      ->getKey(self::QUEUE_KEY_PREFIX, $this->name, 'claimed');
  }

  /**
   * Default contructor
   *
   * Beware that DrupalQueueInterface does not defines the __construct
   * method in the interface yet is being used from DrupalQueue::get()
   *
   * @param unknown $name
   */
  public function __construct($name) {
    $this->name = $name;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DrupalQueueInterface::claimItem public function Claim an item in the queue for processing. 2
DrupalQueueInterface::createItem public function Add a queue item and store it directly to the queue. 2
DrupalQueueInterface::createQueue public function Create a queue. 2
DrupalQueueInterface::deleteItem public function Delete a finished item from the queue. 2
DrupalQueueInterface::deleteQueue public function Delete a queue and every item in the queue. 2
DrupalQueueInterface::numberOfItems public function Retrieve the number of items in the queue. 2
DrupalQueueInterface::releaseItem public function Release an item that the worker could not process, so another worker can come in and process it before the timeout expires. 2
Redis_AbstractBackend::$globalPrefix protected static property
Redis_AbstractBackend::$prefix private property
Redis_AbstractBackend::getClient public function Get redis client
Redis_AbstractBackend::getDefaultPrefix public static function Get global default prefix
Redis_AbstractBackend::getGlobalPrefix public static function Get site default global prefix
Redis_AbstractBackend::getKey public function Get full key name using the set prefix 2
Redis_AbstractBackend::getPrefix final public function Get prefix
Redis_AbstractBackend::KEY_SEPARATOR constant Key components name separator
Redis_AbstractBackend::setPrefix final public function Set prefix
Redis_Queue_Base::$name protected property Queue name
Redis_Queue_Base::getKeyForClaimed public function Get claimed LIST key
Redis_Queue_Base::getKeyForData public function Get data HASH key
Redis_Queue_Base::getKeyForQueue public function Get queued items LIST key
Redis_Queue_Base::QUEUE_HKEY_SEQ constant Data HASH sequence key name.
Redis_Queue_Base::QUEUE_KEY_PREFIX constant Key prefix for queue data.
Redis_Queue_Base::__construct public function Default contructor Overrides Redis_AbstractBackend::__construct