Merge branch 'v1.0'

This commit is contained in:
as2252258@163.com
2021-07-03 13:01:49 +08:00
3 changed files with 203 additions and 200 deletions
+6 -1
View File
@@ -37,6 +37,8 @@ class Connection extends Component
public string $charset = 'utf-8'; public string $charset = 'utf-8';
public string $tablePrefix = ''; public string $tablePrefix = '';
public string $database = '';
public int $timeout = 1900; public int $timeout = 1900;
public int $maxNumber = 200; public int $maxNumber = 200;
@@ -172,7 +174,10 @@ class Connection extends Component
public function masterInstance(): PDO public function masterInstance(): PDO
{ {
return $this->connections()->get([ return $this->connections()->get([
'cds' => $this->cds, 'username' => $this->username, 'password' => $this->password 'cds' => $this->cds,
'username' => $this->username,
'password' => $this->password,
'database' => $this->database
], true); ], true);
} }
+2 -1
View File
@@ -144,7 +144,8 @@ class Connection extends Pool
if (Coroutine::getCid() === -1) { if (Coroutine::getCid() === -1) {
Runtime::enableCoroutine(false); Runtime::enableCoroutine(false);
} }
$link = new PDO($config['cds'], $config['username'], $config['password'], [ $cds = 'mysql:dbname=' . $config['database'] . ';host=' . $config['cds'];
$link = new PDO($cds, $config['username'], $config['password'], [
PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_EMULATE_PREPARES => false,
PDO::ATTR_CASE => PDO::CASE_NATURAL, PDO::ATTR_CASE => PDO::CASE_NATURAL,
PDO::ATTR_TIMEOUT => $this->timeout, PDO::ATTR_TIMEOUT => $this->timeout,
+3 -6
View File
@@ -53,8 +53,7 @@ class Redis extends Pool
*/ */
public function get(mixed $config, bool $isMaster = false): mixed public function get(mixed $config, bool $isMaster = false): mixed
{ {
$name = $config['host'] . ':' . $config['prefix'] . ':' . $config['databases']; $coroutineName = $this->name('redis', 'redis:' . $config['host'], $isMaster);
$coroutineName = $this->name('redis', 'redis:' . $name, $isMaster);
if (!Context::hasContext($coroutineName)) { if (!Context::hasContext($coroutineName)) {
return Context::setContext($coroutineName, $this->getFromChannel($coroutineName, $config)); return Context::setContext($coroutineName, $this->getFromChannel($coroutineName, $config));
} }
@@ -100,8 +99,7 @@ class Redis extends Pool
*/ */
public function release(array $config, bool $isMaster = false) public function release(array $config, bool $isMaster = false)
{ {
$name = $config['host'] . ':' . $config['prefix'] . ':' . $config['databases']; $coroutineName = $this->name('redis', 'redis:' . $config['host'], $isMaster);
$coroutineName = $this->name('redis', 'redis:' . $name, $isMaster);
if (!Context::hasContext($coroutineName)) { if (!Context::hasContext($coroutineName)) {
return; return;
} }
@@ -118,8 +116,7 @@ class Redis extends Pool
*/ */
public function destroy(array $config, bool $isMaster = false) public function destroy(array $config, bool $isMaster = false)
{ {
$name = $config['host'] . ':' . $config['prefix'] . ':' . $config['databases']; $coroutineName = $this->name('redis', 'redis:' . $config['host'], $isMaster);
$coroutineName = $this->name('redis', 'redis:' . $name, $isMaster);
if (Context::hasContext($coroutineName)) { if (Context::hasContext($coroutineName)) {
$this->decrement($coroutineName); $this->decrement($coroutineName);
} }