You are here

function Redis_Cache_PhpRedis::get in Redis 7.2

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

Class

Redis_Cache_PhpRedis
Predis cache backend.

Code

function get($cid) {
  $client = Redis_Client::getClient();
  $key = $this
    ->getKey($cid);
  $cached = $client
    ->hgetall($key);

  // Recent versions of PhpRedis will return the Redis instance
  // instead of an empty array when the HGETALL target key does
  // not exists. I see what you did there.
  if (empty($cached) || !is_array($cached)) {
    return FALSE;
  }
  $cached = (object) $cached;
  if ($cached->serialized) {
    $cached->data = unserialize($cached->data);
  }
  return $cached;
}