From 73be4bb7a2f11768262f3493e84fbf2c490b1629 Mon Sep 17 00:00:00 2001 From: Thomas Hackl <hackl@data-quest.de> Date: Wed, 29 Nov 2023 10:15:30 +0000 Subject: [PATCH] Resolve "Probleme mit dem Redis-Cache in Stud.IP" Closes #3513 Merge request studip/studip!2400 --- lib/classes/StudipRedisCache.class.php | 14 +++++++++++--- resources/vue/components/RedisCacheConfig.vue | 13 +++++++++++-- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/lib/classes/StudipRedisCache.class.php b/lib/classes/StudipRedisCache.class.php index c485b787b52..7b9570bdd0c 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)); } /** diff --git a/resources/vue/components/RedisCacheConfig.vue b/resources/vue/components/RedisCacheConfig.vue index ae254b9e7ec..ad035b37f03 100644 --- a/resources/vue/components/RedisCacheConfig.vue +++ b/resources/vue/components/RedisCacheConfig.vue @@ -2,16 +2,20 @@ <div> <label class="col-4"> <span class="required"> - <translate>Hostname</translate> + {{ $gettext('Hostname') }} </span> <input required type="text" name="hostname" placeholder="localhost" v-model="theHostname"> </label> <label class="col-2"> <span class="required"> - <translate>Port</translate> + {{ $gettext('Port') }} </span> <input required type="text" name="port" placeholder="6379" v-model="thePort"> </label> + <label> + {{ $gettext('Passwort/Token zur Authentifizierung') }} + <input type="text" name="auth" v-model="theAuth"> + </label> </div> </template> @@ -26,12 +30,17 @@ export default { port: { type: Number, default: 6379 + }, + auth: { + type: String, + default: '' } }, data () { return { theHostname: this.hostname, thePort: this.port, + theAuth: this.auth } }, methods: { -- GitLab