From 457d8c22541a27791d1c8541c42c79f16b22511d Mon Sep 17 00:00:00 2001 From: zyx0814 Date: Wed, 7 Feb 2024 00:12:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=86=85=E5=AD=98=E7=BC=93=E5=AD=98=20?= =?UTF-8?q?=E6=A3=80=E6=B5=8B=E5=8A=A0=E5=BC=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/class/memory/memory_driver_memcache.php | 13 +++++++++++-- core/class/memory/memory_driver_memcached.php | 15 ++++++++++++++- core/class/memory/memory_driver_redis.php | 13 +++++++++++-- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/core/class/memory/memory_driver_memcache.php b/core/class/memory/memory_driver_memcache.php index 2b14d7b..f2af38e 100644 --- a/core/class/memory/memory_driver_memcache.php +++ b/core/class/memory/memory_driver_memcache.php @@ -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); } diff --git a/core/class/memory/memory_driver_memcached.php b/core/class/memory/memory_driver_memcached.php index 7cffd49..8c4bfa9 100644 --- a/core/class/memory/memory_driver_memcached.php +++ b/core/class/memory/memory_driver_memcached.php @@ -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(); diff --git a/core/class/memory/memory_driver_redis.php b/core/class/memory/memory_driver_redis.php index 99bb3ad..77b6b1d 100644 --- a/core/class/memory/memory_driver_redis.php +++ b/core/class/memory/memory_driver_redis.php @@ -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)) {