This commit is contained in:
2021-01-05 18:30:58 +08:00
parent f1fd58f794
commit 6d3de65dbb
2 changed files with 27 additions and 2 deletions
+14 -1
View File
@@ -226,6 +226,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) {
$link = new PDO($cds, $username, $password, [
PDO::ATTR_EMULATE_PREPARES => false,
@@ -238,7 +239,7 @@ class Connection extends Pool
if (!empty($charset)) {
$link->query('SET NAMES ' . $charset);
}
$this->success('create client[address: ' . $cds . ', coroutine: ' . Coroutine::getCid() . ', has num: ' . $this->size($coroutineName) . ', has create: ' . $this->hasCreate[$coroutineName] . ']');
$this->printClients($cds, $coroutineName);
$this->incr($coroutineName);
if ($number = Context::getContext('begin_' . $coroutineName, Coroutine::getCid())) {
$number > 0 && $link->beginTransaction();
@@ -253,6 +254,7 @@ class Connection extends Pool
/**
* @param $config
* @param $name
* @return array
*/
private function parseConfig($config, $name): array
@@ -261,6 +263,17 @@ class Connection extends Pool
}
/**
* @param $cds
* @param $coroutineName
* @param false $isBefore
*/
public function printClients($cds, $coroutineName, $isBefore = false)
{
$this->success(($isBefore ? 'before ' : '') . 'create client[address: ' . $cds . ', coroutine: ' . Coroutine::getCid() . ', has num: ' . $this->size($coroutineName) . ', has create: ' . $this->hasCreate[$coroutineName] . ']');
}
/**
* @param $coroutineName
* @param $isMaster
+13 -1
View File
@@ -77,6 +77,7 @@ class Redis extends Pool
*/
private function newClient($config, $coroutineName): \Redis|null
{
$this->printClients($config['cds'], $coroutineName, true);
return $this->createConnect([$config, $coroutineName], $coroutineName, function ($config, $coroutineName) {
$redis = new SRedis();
if (!$redis->connect($config['host'], (int)$config['port'], $config['timeout'])) {
@@ -85,7 +86,7 @@ class Redis extends Pool
if (empty($config['auth']) || !$redis->auth($config['auth'])) {
throw new RedisConnectException(sprintf('Redis Error: %s, Host %s, Auth %s', $redis->getLastError(), $config['host'], $config['auth']));
}
$this->success('create client[address: ' . $config['host'] . ', coroutine: ' . Coroutine::getCid() . ', has num: ' . $this->size($coroutineName) . ', has create: ' . $this->_create . ']');
$this->printClients($config['host'], $coroutineName);
if (!isset($config['read_timeout'])) {
$config['read_timeout'] = 10;
}
@@ -98,6 +99,17 @@ class Redis extends Pool
}
/**
* @param $cds
* @param $coroutineName
* @param false $isBefore
*/
public function printClients($cds, $coroutineName, $isBefore = false)
{
$this->success(($isBefore ? 'before ' : '') . 'create client[address: ' . $cds . ', coroutine: ' . Coroutine::getCid() . ', has num: ' . $this->size($coroutineName) . ', has create: ' . $this->hasCreate[$coroutineName] . ']');
}
/**
* @param $coroutineName
* @param $client