This commit is contained in:
as2252258@163.com
2021-07-03 12:57:06 +08:00
parent 4096050303
commit d7b84a804d
3 changed files with 201 additions and 200 deletions
+4 -1
View File
@@ -174,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);
} }