function Redis_Cache_PhpRedis::getMultiple in Redis 7
Same name and namespace in other branches
- 7.3 lib/Redis/Cache/PhpRedis.php \Redis_Cache_PhpRedis::getMultiple()
- 7.2 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 40
Class
- Redis_Cache_PhpRedis
- 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 (FALSE === $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;
}