aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorThomas Hackl <hackl@data-quest.de>2023-11-29 10:15:30 +0000
committerThomas Hackl <hackl@data-quest.de>2023-11-29 10:15:30 +0000
commit73be4bb7a2f11768262f3493e84fbf2c490b1629 (patch)
tree4a3af8d0136044b795e483de1602f93e4a4e1723 /lib
parent1d1f846c20af881321e3e4d5a6390879dd5d9c4c (diff)
Resolve "Probleme mit dem Redis-Cache in Stud.IP"
Closes #3513 Merge request studip/studip!2400
Diffstat (limited to 'lib')
-rw-r--r--lib/classes/StudipRedisCache.class.php14
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/classes/StudipRedisCache.class.php b/lib/classes/StudipRedisCache.class.php
index c485b78..7b9570b 100644
--- a/lib/classes/StudipRedisCache.class.php
+++ b/lib/classes/StudipRedisCache.class.php
@@ -27,8 +27,9 @@ class StudipRedisCache implements StudipCache
*
* @param string $hostname Hostname of redis server
* @param int $port Port of redis server
+ * @param string $auth Optional auth token/password
*/
- public function __construct($hostname, $port)
+ public function __construct($hostname, $port, string $auth = '')
{
if (!extension_loaded('redis')) {
throw new Exception('Redis extension missing.');
@@ -40,6 +41,10 @@ class StudipRedisCache implements StudipCache
if (!$status) {
throw new Exception('Could not add cache.');
}
+
+ if ($auth !== '') {
+ $this->redis->auth($auth);
+ }
}
/**
@@ -83,7 +88,10 @@ class StudipRedisCache implements StudipCache
public function read($arg)
{
$key = $this->getCacheKey($arg);
- return $this->redis->get($key);
+
+ $result = $this->redis->get($key);
+
+ return ($result === null) ? null : unserialize($result);
}
/**
@@ -97,7 +105,7 @@ class StudipRedisCache implements StudipCache
public function write($name, $content, $expire = self::DEFAULT_EXPIRATION)
{
$key = $this->getCacheKey($name);
- return $this->redis->setEx($key, $expire, $content);
+ return $this->redis->setEx($key, $expire, serialize($content));
}
/**