Skip to content

Commit

Permalink
Merge pull request codeigniter4#8155 from kenjis/refactor-redis-ttl
Browse files Browse the repository at this point in the history
refactor: RedisHandler ttl() calls
  • Loading branch information
kenjis committed Nov 6, 2023
2 parents a60c5b0 + 3a2cc73 commit 1c33359
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
5 changes: 0 additions & 5 deletions phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -3036,11 +3036,6 @@
'count' => 1,
'path' => __DIR__ . '/system/Session/Handlers/RedisHandler.php',
];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in a negated boolean, int given\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Session/Handlers/RedisHandler.php',
];
$ignoreErrors[] = [
'message' => '#^Accessing offset \'HTTP_X_REQUESTED_WITH\' directly on \\$_SERVER is discouraged\\.$#',
'count' => 2,
Expand Down
1 change: 1 addition & 0 deletions system/Cache/Handlers/RedisHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ public function getMetaData(string $key)
if ($value !== null) {
$time = Time::now()->getTimestamp();
$ttl = $this->redis->ttl(static::validateKey($key, $this->prefix));
assert(is_int($ttl));

return [
'expire' => $ttl > 0 ? $time + $ttl : null,
Expand Down
5 changes: 4 additions & 1 deletion system/Session/Handlers/RedisHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,10 @@ protected function lockSession(string $sessionID): bool
$attempt = 0;

do {
if (($ttl = $this->redis->ttl($lockKey)) > 0) {
$ttl = $this->redis->ttl($lockKey);
assert(is_int($ttl));

if ($ttl > 0) {
sleep(1);

continue;
Expand Down

0 comments on commit 1c33359

Please sign in to comment.