Merge pull request #13499 from owncloud/issue/13451-redis-json-encode

Issue/13451 redis json encode
This commit is contained in:
Thomas Müller 2015-01-20 14:53:33 +01:00
commit 84bb4cc2e9
2 changed files with 10 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));
}
}

View file

@ -22,6 +22,12 @@ abstract class Cache extends \Test_Cache {
$this->assertEquals('bar', $this->instance->get('foo'));
}
public function testGetArrayAfterSet() {
$this->assertNull($this->instance->get('foo'));
$this->instance->set('foo', ['bar']);
$this->assertEquals(['bar'], $this->instance->get('foo'));
}
public function testDoesNotExistAfterRemove() {
$this->instance->set('foo', 'bar');
$this->instance->remove('foo');