|
@@ -8,7 +8,6 @@ defined('InShopNC') or exit('Access Invalid!');
|
|
|
class CacheRedis extends Cache
|
|
|
{
|
|
|
private $config;
|
|
|
- private $connected;
|
|
|
private $type;
|
|
|
private $prefix;
|
|
|
public function __construct()
|
|
@@ -24,34 +23,45 @@ class CacheRedis extends Cache
|
|
|
private function init_master()
|
|
|
{
|
|
|
static $_cache;
|
|
|
- if (isset($_cache)){
|
|
|
- $this->handler = $_cache;
|
|
|
- }else{
|
|
|
- $func = $this->config['pconnect'] ? 'pconnect' : 'connect';
|
|
|
- $this->handler = new Redis;
|
|
|
- $this->enable = $this->handler->$func($this->config['master']['host'], $this->config['master']['port']);
|
|
|
- $_cache = $this->handler;
|
|
|
+ if (isset($_cache))
|
|
|
+ {
|
|
|
+ if($_cache->isConnected()) {
|
|
|
+ $this->handler = $_cache;
|
|
|
+ return;
|
|
|
+ } else {
|
|
|
+ $_cache->close();
|
|
|
+ Log::record("CacheRedis init_slave disconnect.",Log::DEBUG);
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- private function init_slave(){
|
|
|
- static $_cache;
|
|
|
- if (isset($_cache)){
|
|
|
- $this->handler = $_cache;
|
|
|
- }else{
|
|
|
- $func = $this->config['pconnect'] ? 'pconnect' : 'connect';
|
|
|
- $this->handler = new Redis;
|
|
|
- $this->enable = $this->handler->$func($this->config['slave']['host'], $this->config['slave']['port']);
|
|
|
- $_cache = $this->handler;
|
|
|
- }
|
|
|
+ $func = $this->config['pconnect'] ? 'pconnect' : 'connect';
|
|
|
+ $this->handler = new Redis();
|
|
|
+ $this->enable = $this->handler->$func($this->config['master']['host'], $this->config['master']['port']);
|
|
|
+ $_cache = $this->handler;
|
|
|
}
|
|
|
|
|
|
- private function isConnected() {
|
|
|
- $this->init_master();
|
|
|
- return $this->enable;
|
|
|
+ private function init_slave()
|
|
|
+ {
|
|
|
+ static $_cache;
|
|
|
+ if (isset($_cache))
|
|
|
+ {
|
|
|
+ if($_cache->isConnected()) {
|
|
|
+ $this->handler = $_cache;
|
|
|
+ return;
|
|
|
+ } else {
|
|
|
+ $_cache->close();
|
|
|
+ Log::record("CacheRedis init_slave disconnect.",Log::DEBUG);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $func = $this->config['pconnect'] ? 'pconnect' : 'connect';
|
|
|
+ $this->handler = new Redis();
|
|
|
+ $this->enable = $this->handler->$func($this->config['slave']['host'], $this->config['slave']['port']);
|
|
|
+ $_cache = $this->handler;
|
|
|
}
|
|
|
|
|
|
- public function get($key, $prefix = ''){
|
|
|
+ public function get($key, $prefix = '')
|
|
|
+ {
|
|
|
$this->init_slave();
|
|
|
if (!$this->enable) return false;
|
|
|
$this->type = $prefix;
|
|
@@ -60,7 +70,8 @@ class CacheRedis extends Cache
|
|
|
return unserialize($value);
|
|
|
}
|
|
|
|
|
|
- public function set($key, $value, $prefix = '', $expire = null) {
|
|
|
+ public function set($key, $value, $prefix = '', $expire = null)
|
|
|
+ {
|
|
|
$this->init_master();
|
|
|
if (!$this->enable) return false;
|
|
|
$this->type = $prefix;
|