From 5f97437aee731ea9b99b0e4b99a9c6cc3199d19b Mon Sep 17 00:00:00 2001 From: huangdijia Date: Tue, 2 Feb 2016 11:17:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96redis=E9=A9=B1=E5=8A=A8?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E6=9C=89=E6=95=88=E6=9C=9F=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/session/driver/Redis.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/library/think/session/driver/Redis.php b/library/think/session/driver/Redis.php index 415cd85d..4f0205d3 100644 --- a/library/think/session/driver/Redis.php +++ b/library/think/session/driver/Redis.php @@ -22,7 +22,7 @@ class Redis extends SessionHandler 'port' => 6379, // 端口 'password' => '', // 密码 'expire' => 3600, // 有效期 - 'timeout' => false, // 超时时间 + 'timeout' => 0, // 超时时间 'persistent' => true, // 是否长连接 'session_name' => '', // memcache key前缀 ]; @@ -47,9 +47,9 @@ class Redis extends SessionHandler $this->handler = new \Redis; // 建立连接 $func = $this->config['persistent'] ? 'pconnect' : 'connect'; - false === $this->config['timeout'] ? - $this->handler->$func($this->config['host'], $this->config['port']) : - $this->handler->$func($this->config['host'], $this->config['port'], $this->config['timeout']); + $this->config['timeout'] > 0 ? + $this->handler->$func($this->config['host'], $this->config['port'], $this->config['timeout']) : + $this->handler->$func($this->config['host'], $this->config['port']); if ('' != $this->config['password']) { $this->handler->auth($this->config['password']); } @@ -86,7 +86,11 @@ class Redis extends SessionHandler */ public function write($sessID, $sessData) { - return $this->handler->set($this->config['session_name'] . $sessID, $sessData, 0, $this->config['expire']); + if($this->handler->set($this->config['session_name'] . $sessID, $sessData)){ + $this->handler->expire($this->config['session_name'] . $sessID, $this->config['expire']); + return true; + } + return false; } /**