格式化和注释

This commit is contained in:
7IN0SAN9
2016-01-25 15:55:21 +08:00
parent c6a7b9e6cb
commit abd9ab924a
2 changed files with 115 additions and 83 deletions

View File

@@ -1,8 +1,18 @@
<?php <?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
namespace think\session\driver; namespace think\session\driver;
use think\session\Driver;
use think\Config; use think\Config;
use think\session\Driver;
class Memcache extends Driver class Memcache extends Driver
{ {
@@ -22,7 +32,8 @@ class Memcache extends Driver
* @param string $savePath * @param string $savePath
* @param mixed $sessName * @param mixed $sessName
*/ */
public function open($savePath, $sessName) { public function open($savePath, $sessName)
{
// 检测php环境 // 检测php环境
if (!extension_loaded('memcache')) { if (!extension_loaded('memcache')) {
throw new Exception('_NOT_SUPPERT_:memcache'); throw new Exception('_NOT_SUPPERT_:memcache');
@@ -45,7 +56,8 @@ class Memcache extends Driver
* 关闭Session * 关闭Session
* @access public * @access public
*/ */
public function close() { public function close()
{
$this->gc(ini_get('session.gc_maxlifetime')); $this->gc(ini_get('session.gc_maxlifetime'));
$this->handler->close(); $this->handler->close();
$this->handler = null; $this->handler = null;
@@ -57,7 +69,8 @@ class Memcache extends Driver
* @access public * @access public
* @param string $sessID * @param string $sessID
*/ */
public function read($sessID) { public function read($sessID)
{
return $this->handler->get($this->config['session_name'] . $sessID); return $this->handler->get($this->config['session_name'] . $sessID);
} }
@@ -67,7 +80,8 @@ class Memcache extends Driver
* @param string $sessID * @param string $sessID
* @param String $sessData * @param String $sessData
*/ */
public function write($sessID, $sessData) { public function write($sessID, $sessData)
{
return $this->handler->set($this->config['session_name'] . $sessID, $sessData, 0, $this->config['expire']); return $this->handler->set($this->config['session_name'] . $sessID, $sessData, 0, $this->config['expire']);
} }
@@ -76,7 +90,8 @@ class Memcache extends Driver
* @access public * @access public
* @param string $sessID * @param string $sessID
*/ */
public function destroy($sessID) { public function destroy($sessID)
{
return $this->handler->delete($this->config['session_name'] . $sessID); return $this->handler->delete($this->config['session_name'] . $sessID);
} }
@@ -85,7 +100,8 @@ class Memcache extends Driver
* @access public * @access public
* @param string $sessMaxLifeTime * @param string $sessMaxLifeTime
*/ */
public function gc($sessMaxLifeTime) { public function gc($sessMaxLifeTime)
{
return true; return true;
} }
} }

View File

@@ -1,8 +1,18 @@
<?php <?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
namespace think\session\driver; namespace think\session\driver;
use think\session\Driver;
use think\Config; use think\Config;
use think\session\Driver;
class Redis extends Driver class Redis extends Driver
{ {
@@ -23,7 +33,8 @@ class Redis extends Driver
* @param string $savePath * @param string $savePath
* @param mixed $sessName * @param mixed $sessName
*/ */
public function open($savePath, $sessName) { public function open($savePath, $sessName)
{
// 检测php环境 // 检测php环境
if (!extension_loaded('redis')) { if (!extension_loaded('redis')) {
throw new Exception('_NOT_SUPPERT_:redis'); throw new Exception('_NOT_SUPPERT_:redis');
@@ -44,7 +55,8 @@ class Redis extends Driver
* 关闭Session * 关闭Session
* @access public * @access public
*/ */
public function close() { public function close()
{
$this->gc(ini_get('session.gc_maxlifetime')); $this->gc(ini_get('session.gc_maxlifetime'));
$this->handler->close(); $this->handler->close();
$this->handler = null; $this->handler = null;
@@ -56,7 +68,8 @@ class Redis extends Driver
* @access public * @access public
* @param string $sessID * @param string $sessID
*/ */
public function read($sessID) { public function read($sessID)
{
return $this->handler->get($this->config['session_name'] . $sessID); return $this->handler->get($this->config['session_name'] . $sessID);
} }
@@ -66,7 +79,8 @@ class Redis extends Driver
* @param string $sessID * @param string $sessID
* @param String $sessData * @param String $sessData
*/ */
public function write($sessID, $sessData) { public function write($sessID, $sessData)
{
return $this->handler->set($this->config['session_name'] . $sessID, $sessData, 0, $this->config['expire']); return $this->handler->set($this->config['session_name'] . $sessID, $sessData, 0, $this->config['expire']);
} }
@@ -75,7 +89,8 @@ class Redis extends Driver
* @access public * @access public
* @param string $sessID * @param string $sessID
*/ */
public function destroy($sessID) { public function destroy($sessID)
{
return $this->handler->delete($this->config['session_name'] . $sessID); return $this->handler->delete($this->config['session_name'] . $sessID);
} }
@@ -84,7 +99,8 @@ class Redis extends Driver
* @access public * @access public
* @param string $sessMaxLifeTime * @param string $sessMaxLifeTime
*/ */
public function gc($sessMaxLifeTime) { public function gc($sessMaxLifeTime)
{
return true; return true;
} }
} }