This commit is contained in:
2021-02-16 23:42:13 +08:00
parent cc1daf9e37
commit 045e73bd63
3 changed files with 18 additions and 18 deletions
+5 -8
View File
@@ -151,7 +151,10 @@ class Connection extends Pool
return Context::getContext($coroutineName);
}
if (!$this->hasItem($coroutineName)) {
return Context::setContext($coroutineName, $this->newClient($config, $coroutineName));
if (($client = $this->newClient($config, $coroutineName)) == true) {
return Context::getContext($coroutineName);
}
return Context::setContext($coroutineName, $client);
}
[$time, $connections] = $this->get($coroutineName);
if (!($connections instanceof PDO)) {
@@ -169,7 +172,7 @@ class Connection extends Pool
*/
private function newClient($config, $coroutineName): PDO|null
{
$connections = $this->createConnect($this->parseConfig($config, $coroutineName), $coroutineName, function ($cds, $username, $password, $charset, $coroutineName) {
return $this->createConnect($this->parseConfig($config, $coroutineName), $coroutineName, function ($cds, $username, $password, $charset, $coroutineName) {
$link = new PDO($cds, $username, $password, [
PDO::ATTR_EMULATE_PREPARES => false,
PDO::ATTR_CASE => PDO::CASE_NATURAL,
@@ -190,12 +193,6 @@ class Connection extends Pool
}
return $link;
});
if ($connections === false) {
Coroutine::sleep(0.003);
return $this->getConnection($config, $coroutineName);
}
$this->printClients($config['cds'], $coroutineName, true);
return $connections;
}
+7 -9
View File
@@ -47,11 +47,14 @@ class Redis extends Pool
return Context::getContext($coroutineName);
}
if (!$this->hasItem($coroutineName)) {
return Context::setContext($coroutineName, $this->newClient($config, $coroutineName));
if (($client = $this->newClient($config, $coroutineName)) == true) {
return Context::getContext($coroutineName);
}
return Context::setContext($coroutineName, $client);
}
[$time, $clients] = $this->get($coroutineName);
if ($clients === null) {
return Context::setContext($coroutineName, $this->newClient($config, $coroutineName));
throw new Exception('Redis exception.');
}
return Context::setContext($coroutineName, $clients);
}
@@ -65,7 +68,8 @@ class Redis extends Pool
*/
private function newClient($config, $coroutineName): \Redis|null
{
$client = $this->createConnect([$config, $coroutineName], $coroutineName, function ($config, $coroutineName) {
$this->printClients($config['host'], $coroutineName, true);
return $this->createConnect([$config, $coroutineName], $coroutineName, function ($config, $coroutineName) {
$redis = new SRedis();
if (!$redis->connect($config['host'], (int)$config['port'], $config['timeout'])) {
throw new RedisConnectException(sprintf('The Redis Connect %s::%d Fail.', $config['host'], $config['port']));
@@ -88,12 +92,6 @@ class Redis extends Pool
return $redis;
});
if ($client === false) {
Coroutine::sleep(0.003);
return $this->getConnection($config, $coroutineName);
}
$this->printClients($config['host'], $coroutineName, true);
return $client;
}