Json_(en|de)code values on redis to be able to cache arrays

This commit is contained in:
Joas Schilling 2015-01-20 10:51:27 +01:00
parent 7eb8404040
commit e25998df0f
1 changed files with 4 additions and 4 deletions

View File

@ -49,18 +49,18 @@ class Redis extends Cache {
public function get($key) {
$result = self::$cache->get($this->getNamespace() . $key);
if ($result === false and ! self::$cache->exists($this->getNamespace() . $key)) {
if ($result === false && !self::$cache->exists($this->getNamespace() . $key)) {
return null;
} else {
return $result;
return json_decode($result, true);
}
}
public function set($key, $value, $ttl = 0) {
if ($ttl > 0) {
return self::$cache->setex($this->getNamespace() . $key, $ttl, $value);
return self::$cache->setex($this->getNamespace() . $key, $ttl, json_encode($value));
} else {
return self::$cache->set($this->getNamespace() . $key, $value);
return self::$cache->set($this->getNamespace() . $key, json_encode($value));
}
}