mirror of
https://github.com/vichan-devel/vichan.git
synced 2025-02-02 12:57:35 +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) {
|
||||
$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)) {
|
||||
throw new \RuntimeException('Unable to connect to Redis!');
|
||||
}
|
||||
@ -26,14 +29,14 @@ class RedisCacheDriver implements CacheDriver {
|
||||
if ($ret === false) {
|
||||
return null;
|
||||
}
|
||||
return \json_decode($ret, true);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function set(string $key, mixed $value, mixed $expires = false): void {
|
||||
if ($expires === false) {
|
||||
$this->inner->set($this->prefix . $key, \json_encode($value));
|
||||
$this->inner->set($this->prefix . $key, $value);
|
||||
} 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