内存缓存 检测加强

This commit is contained in:
zyx0814
2024-02-07 00:12:45 +08:00
Unverified
parent 3a1062766d
commit 457d8c2254
3 changed files with 36 additions and 5 deletions

View File

@@ -20,10 +20,19 @@ class memory_driver_memcache
$connect = @$this->obj->connect($config['server'], $config['port']);
}
$this->enable = $connect ? true : false;
$this->enable = $this->checkEnable($connect);
}
}
public function checkEnable($connect){
if($connect){
$this->set('_check_','_check_',10);
if($this->get('_check_')=='_check_'){
return true;
}
$this->rm('_check_');
}
return false;
}
public function get($key) {
return $this->obj->get($key);
}

View File

@@ -12,9 +12,22 @@ class memory_driver_memcached
public function init($config) {
if(!empty($config['server'])) {
$this->obj = new Memcached();
$connect = $this->connectd($config['server'], $config['port']);
$this->enable = $connect ? true : false;
$this->enable=$this->checkEnable($connect);
}
}
public function checkEnable($connect){
if($connect){
$this->set('_check_','_check_',10);
if($this->get('_check_')=='_check_'){
return true;
}
$this->rm('_check_');
}
return false;
}
public function connectd($host , $port){
$servers = $this->obj->getServerList();

View File

@@ -18,7 +18,7 @@ class memory_driver_redis
} catch (RedisException $e) {
echo $e;
}
$this->enable = $connect ? true : false;
$this->enable = $this->checkEnable($connect);
if($this->enable) {
if($config['requirepass']) {
$this->obj->auth($config['requirepass']);
@@ -27,7 +27,16 @@ class memory_driver_redis
}
}
}
public function checkEnable($connect){
if($connect){
$this->set('_check_','_check_',10);
if($this->get('_check_')=='_check_'){
return true;
}
$this->rm('_check_');
}
return false;
}
function &instance() {
static $object;
if(empty($object)) {