You are here

function Redis_Cache_Predis::getMultiple in Redis 7

Same name and namespace in other branches
  1. 7.3 lib/Redis/Cache/Predis.php \Redis_Cache_Predis::getMultiple()
  2. 7.2 lib/Redis/Cache/Predis.php \Redis_Cache_Predis::getMultiple()

Returns data from the persistent cache when given an array of cache IDs.

Parameters

$cids: An array of cache IDs for the data to retrieve. This is passed by reference, and will have the IDs successfully returned from cache removed.

Return value

An array of the items successfully returned from cache indexed by cid.

Overrides DrupalCacheInterface::getMultiple

File

lib/Redis/Cache/Predis.php, line 45

Class

Redis_Cache_Predis
Predis cache backend.

Code

function getMultiple(&$cids) {
  $client = Redis_Client::getClient();
  $ret = $keys = $exclude = array();
  foreach ($cids as $cid) {
    $key = $this
      ->_buildKey($cid);
    $keys[] = $key . ':data';
    $keys[] = $key . ':serialized';
  }
  $result = $client
    ->mget($keys);
  $index = 0;
  foreach ($cids as $cid) {
    $serialized = $result[$index + 1];
    if (!$serialized) {
      $exclude[$cid] = TRUE;
      continue;
    }
    $cached = new stdClass();
    $cached->data = $result[$index];
    $cached->expires = 0;

    // FIXME: See comment in get() method.
    if ($serialized) {
      $cached->data = unserialize($cached->data);
    }
    $ret[$cid] = $cached;
    $index += 2;
  }

  // WTF Drupal, we need to manually remove entries from &$cids.
  foreach ($cids as $index => $cid) {
    if (isset($exclude[$cid])) {
      unset($cids[$index]);
    }
  }
  return $ret;
}