This commit is contained in:
2020-09-17 14:12:14 +08:00
parent 28669399b5
commit 57db5fe495
4 changed files with 370 additions and 375 deletions
+9 -9
View File
@@ -105,7 +105,7 @@ class Connection extends Pool
*/
public function inTransaction($cds)
{
[$coroutineId, $coroutineName] = $this->getIndex($cds, true);
$coroutineName = $this->name($cds, true);
if (!Context::hasContext('begin_' . $coroutineName)) {
return false;
}
@@ -117,7 +117,7 @@ class Connection extends Pool
*/
public function beginTransaction($coroutineName)
{
[$coroutineId, $coroutineName] = $this->getIndex($coroutineName, true);
$coroutineName = $this->name($coroutineName, true);
if (!Context::hasContext('begin_' . $coroutineName)) {
Context::setContext('begin_' . $coroutineName, 0);
}
@@ -136,7 +136,7 @@ class Connection extends Pool
*/
public function commit($coroutineName)
{
[$coroutineId, $coroutineName] = $this->getIndex($coroutineName, true);
$coroutineName = $this->name($coroutineName, true);
if (!Context::hasContext('begin_' . $coroutineName)) {
return;
}
@@ -170,7 +170,7 @@ class Connection extends Pool
*/
public function rollback($coroutineName)
{
[$coroutineId, $coroutineName] = $this->getIndex($coroutineName, true);
$coroutineName = $this->name($coroutineName, true);
if (!Context::hasContext('begin_' . $coroutineName)) {
return;
}
@@ -200,7 +200,7 @@ class Connection extends Pool
if ($this->creates === 0) {
$this->creates = Timer::tick(10000, [$this, 'Heartbeat_detection']);
}
[$coroutineId, $coroutineName] = $this->getIndex($config['cds'], $isMaster);
$coroutineName = $this->name($config['cds'], $isMaster);
if (!isset($this->hasCreate[$coroutineName])) {
$this->hasCreate[$coroutineName] = 0;
}
@@ -210,9 +210,9 @@ class Connection extends Pool
if ($this->size($coroutineName) < 1 && $this->hasCreate[$coroutineName] < $this->max) {
return $this->saveClient($coroutineName, $this->nowClient($coroutineName, $config));
}
[$timeout, $connection] = $client = $this->get($coroutineName);
if ($connection instanceof PDO) {
return $this->saveClient($coroutineName, $connection);
$connections = $client = $this->get($coroutineName);
if ($connections[1] instanceof PDO) {
return $this->saveClient($coroutineName, $connections[1]);
}
return $this->saveClient($coroutineName, $this->nowClient($coroutineName, $config));
}
@@ -252,7 +252,7 @@ class Connection extends Pool
*/
public function release($coroutineName, $isMaster)
{
[$coroutineId, $coroutineName] = $this->getIndex($coroutineName, $isMaster);
$coroutineName = $this->name($coroutineName, $isMaster);
if (!$this->hasClient($coroutineName)) {
return;
}
+6 -16
View File
@@ -36,7 +36,7 @@ class Redis extends Pool
public function getConnection(array $config, $isMaster = false)
{
$name = $config['host'] . ':' . $config['prefix'] . ':' . $config['databases'];
[$coroutineId, $coroutineName] = $this->getIndex('redis:' . $name, $isMaster);
$coroutineName = $this->name('redis:' . $name, $isMaster);
if (Context::hasContext($coroutineName)) {
return Context::getContext($coroutineName);
} else if (!$this->hasItem($coroutineName)) {
@@ -59,11 +59,11 @@ class Redis extends Pool
$this->success('create redis client -> ' . $config['host'] . ':' . $this->size($coroutineName));
return $this->saveClient($coroutineName, $this->createConnect($config));
}
[$time, $client] = $this->get($coroutineName);
if ($client === null) {
$clients = $this->get($coroutineName);
if ($clients[1] === null) {
return $this->getByChannel($coroutineName, $config);
}
return $this->saveClient($coroutineName, $client);
return $this->saveClient($coroutineName, $clients[1]);
}
@@ -109,7 +109,7 @@ class Redis extends Pool
public function release(array $config, $isMaster = false)
{
$name = $config['host'] . ':' . $config['prefix'] . ':' . $config['databases'];
[$coroutineId, $coroutineName] = $this->getIndex('redis:' . $name, $isMaster);
$coroutineName = $this->name('redis:' . $name, $isMaster);
if (!Context::hasContext($coroutineName)) {
return;
}
@@ -127,7 +127,7 @@ class Redis extends Pool
public function destroy(array $config, $isMaster = false)
{
$name = $config['host'] . ':' . $config['prefix'] . ':' . $config['databases'];
[$coroutineId, $coroutineName] = $this->getIndex('redis:' . $name, $isMaster);
$coroutineName = $this->name('redis:' . $name, $isMaster);
if (!Context::hasContext($coroutineName)) {
return;
}
@@ -177,15 +177,5 @@ class Redis extends Pool
// TODO: Implement desc() method.
}
/**
* @param $name
* @param false $isMaster
* @return array
*/
private function getIndex($name, $isMaster = false)
{
return [Coroutine::getCid(), $this->name($name, $isMaster)];
}
}