<?php<liu21st@gmail.com>
namespace framework\components\session\driver;
use framework\base\Container;
class Redis extends \SessionHandler
{
protected $_handler = null;
protected $_conf = [];
public function __construct($config = [])
{
if (!extension_loaded('redis')) {
throw new \Exception('not support: redis', 500);
}
if (empty($config['_name'])) {
$config['_name'] = 'redis';
}
$this->_conf = $config;
Container::getInstance()->getComponent($this->_conf['_name']);
unset($config);
}
public function open($savePath, $sessName)
{
try
{
$this->_handler = Container::getInstance()->getComponent($this->_conf['_name']);
}
catch(\Exception $e)
{
throw new \Exception($e->getMessage(),500);
}
return true;
}
public function close()
{
$this->gc(ini_get('session.gc_maxlifetime'));
unset($this->_handler);
return true;
}
public function read($sessID)
{
return (string) $this->_handler->get($this->_conf['session_name'] . $sessID);
}
public function write($sessID, $sessData)
{
return $this->_handler->set($this->_conf['session_name'] . $sessID, $sessData);
}
public function destroy($sessID)
{
$this->_handler->rm($this->_conf['session_name'] . $sessID);
return true;
}
public function gc($sessMaxLifeTime)
{
return true;
}
}