function Redis_Cache_Predis::get in Redis 7
Same name and namespace in other branches
- 7.3 lib/Redis/Cache/Predis.php \Redis_Cache_Predis::get()
- 7.2 lib/Redis/Cache/Predis.php \Redis_Cache_Predis::get()
Returns data from the persistent cache.
Data may be stored as either plain text or as serialized data. cache_get() will automatically return unserialized objects and arrays.
Parameters
$cid: The cache ID of the data to retrieve.
Return value
The cache or FALSE on failure.
Overrides DrupalCacheInterface::get
File
- lib/
Redis/ Cache/ Predis.php, line 21
Class
- Redis_Cache_Predis
- Predis cache backend.
Code
function get($cid) {
$client = Redis_Client::getClient();
$key = $this
->_buildKey($cid);
list($serialized, $data) = $client
->mget(array(
$key . ':serialized',
$key . ':data',
));
// Fixes http://drupal.org/node/1241922
// FIXME: Not sure this test is fail-proof. Using the PhpRedis extension,
// Redis values returned seems more strongly typed, which allows a safer
// and quicker test here. But using Predis, some returned value are empty
// strings, which makes these tests incoherent, sadly.
if (!is_bool($serialized) && empty($data)) {
return FALSE;
}
$cached = new stdClass();
$cached->data = $serialized ? unserialize($data) : $data;
$cached->expires = 0;
// FIXME: Redis does not seem to allow us to fetch
// expire value. The only solution would be to create
// a new key. Who on earth need this value anyway?
return $cached;
}