mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 15:12:48 +08:00
优化session redis驱动
This commit is contained in:
@@ -18,13 +18,13 @@ class Redis extends SessionHandler
|
|||||||
{
|
{
|
||||||
protected $handler = null;
|
protected $handler = null;
|
||||||
protected $config = [
|
protected $config = [
|
||||||
'host' => '127.0.0.1', // 主机
|
'host' => '127.0.0.1', // redis主机
|
||||||
'port' => 6379, // 端口
|
'port' => 6379, // redis端口
|
||||||
'password' => '', // 密码
|
'password' => '', // 密码
|
||||||
'expire' => 3600, // 有效期
|
'expire' => 3600, // 有效期(秒)
|
||||||
'timeout' => 0, // 超时时间
|
'timeout' => 0, // 超时时间(秒)
|
||||||
'persistent' => true, // 是否长连接
|
'persistent' => true, // 是否长连接
|
||||||
'session_name' => '', // memcache key前缀
|
'session_name' => '', // sessionkey前缀
|
||||||
];
|
];
|
||||||
|
|
||||||
public function __construct($config = [])
|
public function __construct($config = [])
|
||||||
@@ -86,11 +86,11 @@ class Redis extends SessionHandler
|
|||||||
*/
|
*/
|
||||||
public function write($sessID, $sessData)
|
public function write($sessID, $sessData)
|
||||||
{
|
{
|
||||||
if($this->handler->set($this->config['session_name'] . $sessID, $sessData)){
|
if ($this->config['expire'] > 0) {
|
||||||
$this->handler->expire($this->config['session_name'] . $sessID, $this->config['expire']);
|
return $this->handler->setex($this->config['session_name'] . $sessID, $this->config['expire'], $sessData);
|
||||||
return true;
|
} else {
|
||||||
|
return $this->handler->set($this->config['session_name'] . $sessID, $sessData);
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user