You are here

public function Redis_Queue_PhpRedis::claimItem in Redis 7.2

Same name and namespace in other branches
  1. 7.3 lib/Redis/Queue/PhpRedis.php \Redis_Queue_PhpRedis::claimItem()

Claim an item in the queue for processing.

Parameters

$lease_time: How long the processing is expected to take in seconds, defaults to an hour. After this lease expires, the item will be reset and another consumer can claim the item. For idempotent tasks (which can be run multiple times without side effects), shorter lease times would result in lower latency in case a consumer fails. For tasks that should not be run more than once (non-idempotent), a larger lease time will make it more rare for a given task to run multiple times in cases of failure, at the cost of higher latency.

Return value

On success we return an item object. If the queue is unable to claim an item it returns false. This implies a best effort to retrieve an item and either the queue is empty or there is some other non-recoverable problem.

Overrides DrupalQueueInterface::claimItem

File

lib/Redis/Queue/PhpRedis.php, line 53

Class

Redis_Queue_PhpRedis
@todo Set high expire value to the hash for rotation when memory is empty React upon cache clear all and rebuild path list?

Code

public function claimItem($lease_time = 30) {

  // @todo Deal with lease
  $client = $this
    ->getClient();
  $id = $client
    ->rpoplpush($this
    ->getKeyForQueue(), $this
    ->getKeyForClaimed());
  if ($id) {
    if ($item = $client
      ->hget($this
      ->getKeyForData(), $id)) {
      if ($item = unserialize($item)) {
        return $item;
      }
    }
  }
  return false;
}