From 39aeedfe9aa6178f0338bf403c148334c9a37f80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Sandstr=C3=B6m?= Date: Sun, 11 Aug 2019 15:40:59 +0200 Subject: [PATCH] Updated redis session handler to support redis 5.0.x --- system/Session/Handlers/RedisHandler.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/system/Session/Handlers/RedisHandler.php b/system/Session/Handlers/RedisHandler.php index 9368699d89fc..9415638e2e99 100644 --- a/system/Session/Handlers/RedisHandler.php +++ b/system/Session/Handlers/RedisHandler.php @@ -229,7 +229,7 @@ public function write($sessionID, $sessionData): bool if (isset($this->lockKey)) { - $this->redis->setTimeout($this->lockKey, 300); + $this->redis->expire($this->lockKey, 300); if ($this->fingerprint !== ($fingerprint = md5($sessionData)) || $this->keyExists === false) { @@ -243,7 +243,7 @@ public function write($sessionID, $sessionData): bool return false; } - return $this->redis->setTimeout($this->keyPrefix . $sessionID, $this->sessionExpiration); + return $this->redis->expire($this->keyPrefix . $sessionID, $this->sessionExpiration); } return false; @@ -264,9 +264,10 @@ public function close(): bool { try { - if ($this->redis->ping() === '+PONG') + $ping_reply = $this->redis->ping(); + if (($ping_reply === true) || ($ping_reply === '+PONG')) { - isset($this->lockKey) && $this->redis->delete($this->lockKey); + isset($this->lockKey) && $this->redis->del($this->lockKey); if (! $this->redis->close()) { @@ -302,9 +303,9 @@ public function destroy($sessionID): bool { if (isset($this->redis, $this->lockKey)) { - if (($result = $this->redis->delete($this->keyPrefix . $sessionID)) !== 1) + if (($result = $this->redis->del($this->keyPrefix . $sessionID)) !== 1) { - $this->logger->debug('Session: Redis::delete() expected to return 1, got ' . var_export($result, true) . ' instead.'); + $this->logger->debug('Session: Redis::del() expected to return 1, got ' . var_export($result, true) . ' instead.'); } return $this->destroyCookie(); @@ -347,7 +348,7 @@ protected function lockSession(string $sessionID): bool // correct session ID. if ($this->lockKey === $this->keyPrefix . $sessionID . ':lock') { - return $this->redis->setTimeout($this->lockKey, 300); + return $this->redis->expire($this->lockKey, 300); } // 30 attempts to obtain a lock, in case another request already has it @@ -400,7 +401,7 @@ protected function releaseLock(): bool { if (isset($this->redis, $this->lockKey) && $this->lock) { - if (! $this->redis->delete($this->lockKey)) + if (! $this->redis->del($this->lockKey)) { $this->logger->error('Session: Error while trying to free lock for ' . $this->lockKey); return false;