You are here

function Redis_Cache_PhpRedis::getMultiple in Redis 7.2

Same name and namespace in other branches
  1. 7.3 lib/Redis/Cache/PhpRedis.php \Redis_Cache_PhpRedis::getMultiple()
  2. 7 lib/Redis/Cache/PhpRedis.php \Redis_Cache_PhpRedis::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/PhpRedis.php, line 31

Class

Redis_Cache_PhpRedis
Predis cache backend.

Code

function getMultiple(&$cids) {
  $client = Redis_Client::getClient();
  $ret = array();
  $keys = array_map(array(
    $this,
    'getKey',
  ), $cids);
  $pipe = $client
    ->multi(Redis::PIPELINE);
  foreach ($keys as $key) {
    $pipe
      ->hgetall($key);
  }
  $replies = $pipe
    ->exec();
  foreach ($replies as $reply) {
    if (!empty($reply)) {
      $cached = (object) $reply;
      if ($cached->serialized) {
        $cached->data = unserialize($cached->data);
      }
      $ret[$cached->cid] = $cached;
    }
  }
  foreach ($cids as $index => $cid) {
    if (isset($ret[$cid])) {
      unset($cids[$index]);
    }
  }
  return $ret;
}