You are here

function Redis_Cache_Predis::getMultiple in Redis 7.2

Same name and namespace in other branches
  1. 7.3 lib/Redis/Cache/Predis.php \Redis_Cache_Predis::getMultiple()
  2. 7 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 28

Class

Redis_Cache_Predis
Predis cache backend.

Code

function getMultiple(&$cids) {
  $client = Redis_Client::getClient();
  $ret = $keys = array();
  $keys = array_map(array(
    $this,
    'getKey',
  ), $cids);
  $replies = $client
    ->pipeline(function ($pipe) use ($keys) {
    foreach ($keys as $key) {
      $pipe
        ->hgetall($key);
    }
  });
  foreach ($replies as $reply) {
    if (!empty($reply)) {

      // HGETALL signature seems to differ depending on Predis versions.
      // This was found just after Predis update. Even though I'm not sure
      // this comes from Predis or just because we're misusing it.
      // FIXME: Needs some investigation.
      if (!isset($reply['cid'])) {
        $cache = new stdClass();
        $size = count($reply);
        for ($i = 0; $i < $size; ++$i) {
          $cache->{$reply[$i]} = $reply[++$i];
        }
      }
      else {
        $cache = (object) $reply;
      }
      if ($cache->serialized) {
        $cache->data = unserialize($cache->data);
      }
      $ret[$cache->cid] = $cache;
    }
  }
  foreach ($cids as $index => $cid) {
    if (isset($ret[$cid])) {
      unset($cids[$index]);
    }
  }
  return $ret;
}