Skip to content

Commit aa8f7b7

Browse files
bug #39298 [Cache] Fixed incorrect usage of UNLINK with PHPRedis with Redis < 4.0 (wickex)
This PR was merged into the 5.2 branch. Discussion ---------- [Cache] Fixed incorrect usage of UNLINK with PHPRedis with Redis < 4.0 | Q | A | ------------- | --- | Branch? | 5.2 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #39280 | License | MIT Currently, deleting cache keys is broken for users using PhpRedis with Redis-server < 4.0.0. The current implementation expects PhpRedis to throw an exception if the 'unlink'-function is used but unavailable, after which it's supposed to switch to using the 'del'-function. Using the 'unlink'-function on lower Redis-server versions seems to not throw an exception, but instead it appears to silently fail. This pull request changes this behavior and checks the Redis-server version instead. If the version is 4.0 or higher, it uses the unlink function. If not, it uses the del-function. Also see https://redis.io/commands/unlink > "Available since 4.0.0". (Footnote: this is one of my first times contributing to an open-source project and my first time contributing to Symfony. I've tried following the guidelines, but please let me know if I missed anything. I'm unsure how I would go about unit testing this specific bugfix due to it being dependent on the Redis version, so I omitted it. Please let me know if a unit test is indeed required for this and if so, let me know if you have any suggestions on how to go about that.) Commits ------- 9363f3b973 [Cache] Fixed incorrect usage of UNLINK with PHPRedis with Redis < 4.0
2 parents ba17a35 + f83e530 commit aa8f7b7

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Session/Storage/Handler/RedisSessionHandler.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@ protected function doDestroy(string $sessionId): bool
9393

9494
if ($unlink) {
9595
try {
96-
$this->redis->unlink($this->prefix.$sessionId);
97-
98-
return true;
96+
$unlink = false !== $this->redis->unlink($this->prefix.$sessionId);
9997
} catch (\Throwable $e) {
10098
$unlink = false;
10199
}
102100
}
103101

104-
$this->redis->del($this->prefix.$sessionId);
102+
if (!$unlink) {
103+
$this->redis->del($this->prefix.$sessionId);
104+
}
105105

106106
return true;
107107
}

0 commit comments

Comments
 (0)