Skip to content

Commit

Permalink
fix #249 - fix session handler lock key prefix (#503)
Browse files Browse the repository at this point in the history
  • Loading branch information
B-Galati authored and curry684 committed Feb 22, 2019
1 parent 9a679f4 commit 521d237
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions Session/Storage/Handler/RedisSessionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ public function __construct($redis, array $options = array(), $prefix = 'session

$this->locking = $locking;
$this->locked = false;
$this->lockKey = null;
$this->spinLockWait = $spinLockWait;
$this->lockMaxWait = ini_get('max_execution_time');
if (!$this->lockMaxWait) {
Expand Down Expand Up @@ -194,7 +193,7 @@ protected function lockSession($sessionId)
$attempts = (1000000 / $this->spinLockWait) * $this->lockMaxWait;

$this->token = uniqid();
$this->lockKey = $sessionId.'.lock';
$this->lockKey = $this->getRedisKey($sessionId).'.lock';

$setFunction = function ($redis, $key, $token, $ttl) {
if ($redis instanceof \Redis) {
Expand All @@ -217,7 +216,7 @@ protected function lockSession($sessionId)
for ($i = 0;$i < $attempts;++$i) {

// We try to aquire the lock
$success = $setFunction($this->redis, $this->getRedisKey($this->lockKey), $this->token, $this->lockMaxWait * 1000 + 1);
$success = $setFunction($this->redis, $this->lockKey, $this->token, $this->lockMaxWait * 1000 + 1);
if ($success) {
$this->locked = true;

Expand Down Expand Up @@ -246,10 +245,10 @@ private function unlockSession()
LUA;

$token = $this->redis->_serialize($this->token);
$this->redis->eval($script, array($this->getRedisKey($this->lockKey), $token), 1);
$this->redis->eval($script, array($this->lockKey, $token), 1);
} else {
$this->redis->getProfile()->defineCommand('sncFreeSessionLock', 'Snc\RedisBundle\Session\Storage\Handler\FreeLockCommand');
$this->redis->sncFreeSessionLock($this->getRedisKey($this->lockKey), $this->token);
$this->redis->getProfile()->defineCommand('sncFreeSessionLock', FreeLockCommand::class);
$this->redis->sncFreeSessionLock($this->lockKey, $this->token);
}
$this->locked = false;
$this->token = null;
Expand Down

0 comments on commit 521d237

Please sign in to comment.