Skip to content

Commit

Permalink
Merge pull request #7887 from ping-yee/230901_redis_close
Browse files Browse the repository at this point in the history
Fix: [Session] the problem of secondary retrieving values ​​in RedisHandler
  • Loading branch information
kenjis authored Sep 8, 2023
2 parents 64c9a70 + 2b33a11 commit eb1d5e0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion system/Session/Handlers/RedisHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public function close(): bool

if (($pingReply === true) || ($pingReply === '+PONG')) {
if (isset($this->lockKey)) {
$this->redis->del($this->lockKey);
$this->releaseLock();
}

if (! $this->redis->close()) {
Expand Down
22 changes: 22 additions & 0 deletions tests/system/Session/Handlers/Database/RedisHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,26 @@ public function testGC(): void
$handler = $this->getInstance();
$this->assertSame(1, $handler->gc(3600));
}

/**
* See https://github.com/codeigniter4/CodeIgniter4/issues/7695
*/
public function testSecondaryReadAfterClose(): void
{
$handler = $this->getInstance();
$handler->open($this->sessionSavePath, $this->sessionName);

$expected = <<<'DATA'
__ci_last_regenerate|i:1664607454;_ci_previous_url|s:32:"http://localhost:8080/index.php/";key|s:5:"value";
DATA;
$this->assertSame($expected, $handler->read('555556b43phsnnf8if6bo33b635e4447'));

$handler->close();

$handler->open($this->sessionSavePath, $this->sessionName);

$this->assertSame($expected, $handler->read('555556b43phsnnf8if6bo33b635e4447'));

$handler->close();
}
}

0 comments on commit eb1d5e0

Please sign in to comment.