You are here

function Redis_Cache_PhpRedis::get in Redis 7

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

Class

Redis_Cache_PhpRedis
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',
  ));
  if (FALSE === $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;
}