Skip to content
Snippets Groups Projects
Commit 84bb4cc2 authored by Thomas Müller's avatar Thomas Müller
Browse files

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

Issue/13451 redis json encode
parents 02848a50 e25998df
No related branches found
No related tags found
No related merge requests found
...@@ -49,18 +49,18 @@ class Redis extends Cache { ...@@ -49,18 +49,18 @@ class Redis extends Cache {
public function get($key) { public function get($key) {
$result = self::$cache->get($this->getNamespace() . $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; return null;
} else { } else {
return $result; return json_decode($result, true);
} }
} }
public function set($key, $value, $ttl = 0) { public function set($key, $value, $ttl = 0) {
if ($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 { } else {
return self::$cache->set($this->getNamespace() . $key, $value); return self::$cache->set($this->getNamespace() . $key, json_encode($value));
} }
} }
......
...@@ -22,6 +22,12 @@ abstract class Cache extends \Test_Cache { ...@@ -22,6 +22,12 @@ abstract class Cache extends \Test_Cache {
$this->assertEquals('bar', $this->instance->get('foo')); $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() { public function testDoesNotExistAfterRemove() {
$this->instance->set('foo', 'bar'); $this->instance->set('foo', 'bar');
$this->instance->remove('foo'); $this->instance->remove('foo');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment