Skip to content

Commit

Permalink
Updated redis session handler to support redis 5.0.x
Browse files Browse the repository at this point in the history
  • Loading branch information
tangix committed Aug 11, 2019
1 parent 1ed8d36 commit 39aeedf
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions system/Session/Handlers/RedisHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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;
Expand All @@ -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())
{
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 39aeedf

Please sign in to comment.