改名
This commit is contained in:
@@ -124,13 +124,10 @@ abstract class Pool extends Component
|
||||
* @return PDO|Redis|null
|
||||
* @throws Exception
|
||||
*/
|
||||
public function createConnect(array $config, string $coroutineName, callable $createHandler): PDO|Redis|null
|
||||
public function createConnect(array $config, string $coroutineName, callable $createHandler): PDO|Redis|false
|
||||
{
|
||||
if ($this->hasItem($coroutineName)) {
|
||||
return $this->get($coroutineName)[1];
|
||||
}
|
||||
if (Context::hasContext('create:connect:' . $coroutineName)) {
|
||||
return null;
|
||||
return false;
|
||||
}
|
||||
Context::setContext('create:connect:' . $coroutineName, 1);
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@ class Connection extends Pool
|
||||
protected array $connections = [];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param $timeout
|
||||
*/
|
||||
@@ -151,14 +150,13 @@ class Connection extends Pool
|
||||
if (Context::hasContext($coroutineName)) {
|
||||
return Context::getContext($coroutineName);
|
||||
}
|
||||
if ($this->size($coroutineName) < 1) {
|
||||
$connections = $this->newClient($config, $coroutineName);
|
||||
} else {
|
||||
if (!$this->hasItem($coroutineName)) {
|
||||
return Context::setContext($coroutineName, $this->newClient($config, $coroutineName));
|
||||
}
|
||||
[$time, $connections] = $this->get($coroutineName);
|
||||
if (!($connections instanceof PDO)) {
|
||||
throw new Exception('Database exception.');
|
||||
}
|
||||
}
|
||||
return Context::setContext($coroutineName, $connections);
|
||||
}
|
||||
|
||||
@@ -172,7 +170,7 @@ class Connection extends Pool
|
||||
private function newClient($config, $coroutineName): PDO|null
|
||||
{
|
||||
$this->printClients($config['cds'], $coroutineName, true);
|
||||
return $this->createConnect($this->parseConfig($config, $coroutineName), $coroutineName, function ($cds, $username, $password, $charset, $coroutineName) {
|
||||
$connections = $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,
|
||||
@@ -193,6 +191,10 @@ class Connection extends Pool
|
||||
}
|
||||
return $link;
|
||||
});
|
||||
if ($connections === false) {
|
||||
return $this->newClient($config, $coroutineName);
|
||||
}
|
||||
return $connections;
|
||||
}
|
||||
|
||||
|
||||
|
||||
+9
-17
@@ -47,13 +47,13 @@ class Redis extends Pool
|
||||
return Context::getContext($coroutineName);
|
||||
}
|
||||
if (!$this->hasItem($coroutineName)) {
|
||||
return $this->saveClient($coroutineName, $this->newClient($config, $coroutineName));
|
||||
return Context::setContext($coroutineName, $this->newClient($config, $coroutineName));
|
||||
}
|
||||
[$time, $clients] = $this->get($coroutineName);
|
||||
if ($clients === null) {
|
||||
return $this->saveClient($coroutineName, $this->newClient($config, $coroutineName));
|
||||
return Context::setContext($coroutineName, $this->newClient($config, $coroutineName));
|
||||
}
|
||||
return $this->saveClient($coroutineName, $clients);
|
||||
return Context::setContext($coroutineName, $clients);
|
||||
}
|
||||
|
||||
|
||||
@@ -65,8 +65,7 @@ class Redis extends Pool
|
||||
*/
|
||||
private function newClient($config, $coroutineName): \Redis|null
|
||||
{
|
||||
$this->printClients($config['host'], $coroutineName, true);
|
||||
return $this->createConnect([$config, $coroutineName], $coroutineName, function ($config, $coroutineName) {
|
||||
$client = $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']));
|
||||
@@ -89,6 +88,11 @@ class Redis extends Pool
|
||||
|
||||
return $redis;
|
||||
});
|
||||
if ($client === false) {
|
||||
return $this->newClient($config, $coroutineName);
|
||||
}
|
||||
$this->printClients($config['host'], $coroutineName, true);
|
||||
return $client;
|
||||
}
|
||||
|
||||
|
||||
@@ -103,18 +107,6 @@ class Redis extends Pool
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $coroutineName
|
||||
* @param $client
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
private function saveClient($coroutineName, $client): mixed
|
||||
{
|
||||
return Context::setContext($coroutineName, $client);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $config
|
||||
* @param bool $isMaster
|
||||
|
||||
Reference in New Issue
Block a user