This commit is contained in:
2021-02-20 12:29:12 +08:00
parent c718c341ae
commit 2fdefb43c9
2 changed files with 5 additions and 11 deletions
+3 -5
View File
@@ -153,11 +153,11 @@ class Connection extends Pool
return Context::getContext($coroutineName); return Context::getContext($coroutineName);
} }
if (!$this->hasItem($coroutineName)) { if (!$this->hasItem($coroutineName)) {
return $this->newClient($config, $coroutineName); $this->newClient($config, $coroutineName);
} }
[$time, $connections] = $this->get($coroutineName); [$time, $connections] = $this->get($coroutineName);
if (!($connections instanceof PDO)) { if (!($connections instanceof PDO)) {
return $this->newClient($config, $coroutineName); return $this->getConnection($config, $coroutineName);
} }
return Context::setContext($coroutineName, $connections); return Context::setContext($coroutineName, $connections);
} }
@@ -166,10 +166,9 @@ class Connection extends Pool
/** /**
* @param $config * @param $config
* @param $coroutineName * @param $coroutineName
* @return PDO|null
* @throws Exception * @throws Exception
*/ */
private function newClient($config, $coroutineName): PDO|null private function newClient($config, $coroutineName)
{ {
$this->printClients($config['cds'], $coroutineName, true); $this->printClients($config['cds'], $coroutineName, true);
$this->createConnect($this->parseConfig($config, $coroutineName), $coroutineName, function ($cds, $username, $password, $charset, $coroutineName) { $this->createConnect($this->parseConfig($config, $coroutineName), $coroutineName, function ($cds, $username, $password, $charset, $coroutineName) {
@@ -193,7 +192,6 @@ class Connection extends Pool
} }
return $link; return $link;
}); });
return $this->get($coroutineName)[1];
} }
+2 -6
View File
@@ -48,11 +48,11 @@ class Redis extends Pool
return Context::getContext($coroutineName); return Context::getContext($coroutineName);
} }
if (!$this->hasItem($coroutineName)) { if (!$this->hasItem($coroutineName)) {
return $this->newClient($config, $coroutineName); $this->newClient($config, $coroutineName);
} }
[$time, $clients] = $this->get($coroutineName); [$time, $clients] = $this->get($coroutineName);
if ($clients === null) { if ($clients === null) {
return $this->newClient($config, $coroutineName); return $this->getConnection($config, $coroutineName);
} }
return Context::setContext($coroutineName, $clients); return Context::setContext($coroutineName, $clients);
} }
@@ -82,10 +82,6 @@ class Redis extends Pool
$redis->setOption(SRedis::OPT_READ_TIMEOUT, $config['read_timeout']); $redis->setOption(SRedis::OPT_READ_TIMEOUT, $config['read_timeout']);
$redis->setOption(SRedis::OPT_PREFIX, $config['prefix']); $redis->setOption(SRedis::OPT_PREFIX, $config['prefix']);
if ($this->creates === 0) {
$this->creates = Timer::tick(1000, [$this, 'Heartbeat_detection']);
}
$this->_create += 1; $this->_create += 1;
return $redis; return $redis;