From 4f8db41ca1a4c2fa2e8a6113f724d95becf07c52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Fri, 4 Sep 2020 19:00:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- System/Abstracts/Pool.php | 4 ++-- System/Pool/Connection.php | 12 ++++++------ System/Pool/Redis.php | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/System/Abstracts/Pool.php b/System/Abstracts/Pool.php index 145fca5b..85197dc8 100644 --- a/System/Abstracts/Pool.php +++ b/System/Abstracts/Pool.php @@ -109,7 +109,7 @@ abstract class Pool extends Component */ public function hasItem($name) { - return $this->hasLength($name) > 0; + return $this->size($name) > 0; } @@ -117,7 +117,7 @@ abstract class Pool extends Component * @param $name * @return mixed */ - public function hasLength($name) + public function size($name) { if (!isset($this->_items[$name])) { return 0; diff --git a/System/Pool/Connection.php b/System/Pool/Connection.php index c752d327..7c89d39e 100644 --- a/System/Pool/Connection.php +++ b/System/Pool/Connection.php @@ -149,7 +149,7 @@ class Connection extends Pool [$coroutineId, $coroutineName] = $this->getIndex($config['cds'], $isMaster); if (Context::hasContext($coroutineName)) { return Context::getContext($coroutineName); - } else if (!$this->hasItem($coroutineName)) { + } else if ($this->size($coroutineName) < 1) { return $this->saveClient($coroutineName, $this->nowClient($coroutineName, $config)); } else { return $this->getByChannel($coroutineName, $config); @@ -165,10 +165,10 @@ class Connection extends Pool */ public function fill($name, $config) { - if ($this->hasLength($name) >= 10) { + if ($this->size($name) >= 10) { return $this; } - for ($i = 0; $i < 10 - $this->hasLength($name); $i++) { + for ($i = 0; $i < 10 - $this->size($name); $i++) { $this->push($name, $this->createConnect($config['cds'], $config['username'], $config['password'])); } return $this; @@ -182,13 +182,13 @@ class Connection extends Pool */ public function getByChannel($coroutineName, $config) { - $this->info('client has :' . $this->hasLength($coroutineName)); + $this->info('client has :' . $this->size($coroutineName)); [$time, $client] = $this->get($coroutineName, -1); if ($client instanceof PDO) { return $this->saveClient($coroutineName, $client); } unset($client); - if (!$this->hasItem($coroutineName)) { + if ($this->hasItem($coroutineName) < 1) { return $this->saveClient($coroutineName, $this->nowClient($coroutineName, $config)); } return $this->getByChannel($coroutineName, $config); @@ -215,7 +215,7 @@ class Connection extends Pool private function nowClient($coroutineName, $config) { $client = $this->createConnect($config['cds'], $config['username'], $config['password']); - $this->success('create db client -> ' . $config['cds'] . ':' . $this->hasLength($coroutineName)); + $this->success('create db client -> ' . $config['cds'] . ':' . $this->size($coroutineName)); if (isset(Context::getContext('begin_' . $coroutineName)[Coroutine::getCid()])) { $number = Context::getContext('begin_' . $coroutineName)[Coroutine::getCid()]; $number > 0 && $client->beginTransaction(); diff --git a/System/Pool/Redis.php b/System/Pool/Redis.php index e34ddd73..69511d37 100644 --- a/System/Pool/Redis.php +++ b/System/Pool/Redis.php @@ -40,7 +40,7 @@ class Redis extends Pool if (Context::hasContext($coroutineName)) { return Context::getContext($coroutineName); } else if (!$this->hasItem($coroutineName)) { - $this->success('create redis client -> ' . $config['host'] . ':' . $this->hasLength($coroutineName)); + $this->success('create redis client -> ' . $config['host'] . ':' . $this->size($coroutineName)); return $this->saveClient($coroutineName, $this->createConnect($config)); } return $this->getByChannel($coroutineName, $config); @@ -55,9 +55,9 @@ class Redis extends Pool */ public function getByChannel($coroutineName, $config) { - $this->info('redis client has :' . $this->hasLength($coroutineName)); + $this->info('redis client has :' . $this->size($coroutineName)); if (!$this->hasItem($coroutineName)) { - $this->success('create redis client -> ' . $config['host'] . ':' . $this->hasLength($coroutineName)); + $this->success('create redis client -> ' . $config['host'] . ':' . $this->size($coroutineName)); return $this->saveClient($coroutineName, $this->createConnect($config)); } [$time, $client] = $this->get($coroutineName, -1);