mirror of
https://github.com/vichan-devel/vichan.git
synced 2025-02-08 23:39:46 +01:00
RedisCacheDriver.php: use extension provided serialization
This commit is contained in:
parent
30113d3be9
commit
96a6307ff8
@ -14,6 +14,9 @@ class RedisCacheDriver implements CacheDriver {
|
|||||||
if ($password) {
|
if ($password) {
|
||||||
$this->inner->auth($password);
|
$this->inner->auth($password);
|
||||||
}
|
}
|
||||||
|
if (!$this->inner->setOption(\Redis::OPT_SERIALIZER, \Redis::SERIALIZER_JSON)) {
|
||||||
|
throw new \RuntimeException('Unable to configure Redis serializer');
|
||||||
|
}
|
||||||
if (!$this->inner->select($database)) {
|
if (!$this->inner->select($database)) {
|
||||||
throw new \RuntimeException('Unable to connect to Redis!');
|
throw new \RuntimeException('Unable to connect to Redis!');
|
||||||
}
|
}
|
||||||
@ -26,14 +29,14 @@ class RedisCacheDriver implements CacheDriver {
|
|||||||
if ($ret === false) {
|
if ($ret === false) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return \json_decode($ret, true);
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function set(string $key, mixed $value, mixed $expires = false): void {
|
public function set(string $key, mixed $value, mixed $expires = false): void {
|
||||||
if ($expires === false) {
|
if ($expires === false) {
|
||||||
$this->inner->set($this->prefix . $key, \json_encode($value));
|
$this->inner->set($this->prefix . $key, $value);
|
||||||
} else {
|
} else {
|
||||||
$this->inner->setEx($this->prefix . $key, $expires, \json_encode($value));
|
$this->inner->setEx($this->prefix . $key, $expires, $value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user