Skip to content

Commit

Permalink
bug #34827 [HttpFoundation] get currently session.gc_maxlifetime if t…
Browse files Browse the repository at this point in the history
…tl doesnt exists (rafaeltovar)

This PR was submitted for the master branch but it was squashed and merged into the 4.4 branch instead.

Discussion
----------

[HttpFoundation] get currently session.gc_maxlifetime if ttl doesnt exists

| Q             | A
| ------------- | ---
| Branch?       | master / 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #34659
| License       | MIT

If option `ttl` was not defined in RedisSessionHandler, this got the default `session.gc_maxlifetime`. With this fixed, RedisSessionHandler get the currently `session.gc_maxlifetime`.

Commits
-------

b6253e2 [HttpFoundation] get currently session.gc_maxlifetime if ttl doesnt exists
  • Loading branch information
nicolas-grekas committed Dec 6, 2019
2 parents bfe697b + b6253e2 commit 0ad5dd5
Showing 1 changed file with 3 additions and 3 deletions.
Expand Up @@ -63,7 +63,7 @@ public function __construct($redis, array $options = [])

$this->redis = $redis;
$this->prefix = $options['prefix'] ?? 'sf_s';
$this->ttl = $options['ttl'] ?? (int) ini_get('session.gc_maxlifetime');
$this->ttl = $options['ttl'] ?? null;
}

/**
Expand All @@ -79,7 +79,7 @@ protected function doRead($sessionId): string
*/
protected function doWrite($sessionId, $data): bool
{
$result = $this->redis->setEx($this->prefix.$sessionId, $this->ttl, $data);
$result = $this->redis->setEx($this->prefix.$sessionId, (int) ($this->ttl ?? ini_get('session.gc_maxlifetime')), $data);

return $result && !$result instanceof ErrorInterface;
}
Expand Down Expand Up @@ -115,6 +115,6 @@ public function gc($maxlifetime): bool
*/
public function updateTimestamp($sessionId, $data)
{
return (bool) $this->redis->expire($this->prefix.$sessionId, $this->ttl);
return (bool) $this->redis->expire($this->prefix.$sessionId, (int) ($this->ttl ?? ini_get('session.gc_maxlifetime')));
}
}

0 comments on commit 0ad5dd5

Please sign in to comment.