Skip to content

Commit 21436f6

Browse files
PHPREDIS-1354: Added session lifetime parameter for reading session data
1 parent e2d5b5e commit 21436f6

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

tests/RedisTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5493,7 +5493,7 @@ public function testSession_ttl_resetOnRead()
54935493
$sessionId = $this->generateSessionId();
54945494
$this->startSessionProcess($sessionId, 0, false, 300, true, null, -1, 0, 'test', 600);
54955495
$this->redis->expire($this->sessionPrefix . $sessionId, 9999);
5496-
$this->getSessionData($sessionId);
5496+
$this->getSessionData($sessionId, 600);
54975497
$ttl = $this->redis->ttl($this->sessionPrefix . $sessionId);
54985498

54995499
$this->assertEquals(600, $ttl);
@@ -5565,12 +5565,13 @@ private function startSessionProcess($sessionId, $sleepTime, $background, $maxEx
55655565

55665566
/**
55675567
* @param string $sessionId
5568+
* @param int $sessionLifetime
55685569
*
55695570
* @return string
55705571
*/
5571-
private function getSessionData($sessionId)
5572+
private function getSessionData($sessionId, $sessionLifetime = 1440)
55725573
{
5573-
$command = 'php ' . __DIR__ . '/getSessionData.php ' . escapeshellarg($this->getHost()) . ' ' . escapeshellarg($sessionId);
5574+
$command = 'php ' . __DIR__ . '/getSessionData.php ' . escapeshellarg($this->getHost()) . ' ' . escapeshellarg($sessionId) . ' ' . escapeshellarg($sessionLifetime);
55745575
exec($command, $output);
55755576

55765577
return $output[0];

tests/getSessionData.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33

44
$redisHost = $argv[1];
55
$sessionId = $argv[2];
6+
$sessionLifetime = $argv[3];
67

78
if (empty($redisHost)) {
89
$redisHost = 'localhost';
910
}
1011

1112
ini_set('session.save_handler', 'redis');
1213
ini_set('session.save_path', 'tcp://' . $redisHost . ':6379');
14+
ini_set('session.gc_maxlifetime', $sessionLifetime);
1315

1416
session_id($sessionId);
1517
if (!session_start()) {

0 commit comments

Comments
 (0)