From 569cf69078de1c8a970ab4259467dfe27b4cdb96 Mon Sep 17 00:00:00 2001 From: tianhe1986 Date: Wed, 5 Jul 2017 16:54:01 +0800 Subject: Acquiring redis lock with existence check. Signed-off-by: tianhe1986 --- system/libraries/Session/drivers/Session_redis_driver.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'system/libraries/Session') diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php index 2aeb77267..8fc0a45da 100644 --- a/system/libraries/Session/drivers/Session_redis_driver.php +++ b/system/libraries/Session/drivers/Session_redis_driver.php @@ -365,7 +365,16 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle continue; } - if ( ! $this->_redis->setex($lock_key, 300, time())) + if ($ttl === -2) + { + $set_result = $this->_redis->set($lock_key, time(), array('nx', 'ex' => 300)); + } + else + { + $set_result = $this->_redis->setex($lock_key, 300, time()); + } + + if ( ! $set_result) { log_message('error', 'Session: Error while trying to obtain lock for '.$this->_key_prefix.$session_id); return FALSE; -- cgit v1.2.3-24-g4f1b