Skip to content

Commit eb1d5e0

Browse files
authored
Merge pull request #7887 from ping-yee/230901_redis_close
Fix: [Session] the problem of secondary retrieving values ​​in RedisHandler
2 parents 64c9a70 + 2b33a11 commit eb1d5e0

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

system/Session/Handlers/RedisHandler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ public function close(): bool
223223

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

229229
if (! $this->redis->close()) {

tests/system/Session/Handlers/Database/RedisHandlerTest.php

+22
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,26 @@ public function testGC(): void
168168
$handler = $this->getInstance();
169169
$this->assertSame(1, $handler->gc(3600));
170170
}
171+
172+
/**
173+
* See https://github.com/codeigniter4/CodeIgniter4/issues/7695
174+
*/
175+
public function testSecondaryReadAfterClose(): void
176+
{
177+
$handler = $this->getInstance();
178+
$handler->open($this->sessionSavePath, $this->sessionName);
179+
180+
$expected = <<<'DATA'
181+
__ci_last_regenerate|i:1664607454;_ci_previous_url|s:32:"http://localhost:8080/index.php/";key|s:5:"value";
182+
DATA;
183+
$this->assertSame($expected, $handler->read('555556b43phsnnf8if6bo33b635e4447'));
184+
185+
$handler->close();
186+
187+
$handler->open($this->sessionSavePath, $this->sessionName);
188+
189+
$this->assertSame($expected, $handler->read('555556b43phsnnf8if6bo33b635e4447'));
190+
191+
$handler->close();
192+
}
171193
}

0 commit comments

Comments
 (0)