This commit is contained in:
2021-02-03 18:35:52 +08:00
parent e28278e93b
commit 7e110559bc
2 changed files with 9 additions and 19 deletions
+4 -1
View File
@@ -146,7 +146,10 @@ abstract class Pool extends Component
*/ */
public function hasItem(string $name): bool public function hasItem(string $name): bool
{ {
return $this->size($name) > 0; if (isset($this->_items[$name])) {
return $this->_items[$name]->isEmpty();
}
return false;
} }
+3 -16
View File
@@ -45,25 +45,12 @@ class Redis extends Pool
if (Context::hasContext($coroutineName)) { if (Context::hasContext($coroutineName)) {
return Context::getContext($coroutineName); return Context::getContext($coroutineName);
} }
return $this->getByChannel($coroutineName, $config);
}
/**
* @param $coroutineName
* @param $config
* @return mixed
* @throws Exception
*/
public function getByChannel($coroutineName, $config): mixed
{
if (!$this->hasItem($coroutineName)) { if (!$this->hasItem($coroutineName)) {
$clients = $this->newClient($config, $coroutineName); return $this->saveClient($coroutineName, $this->newClient($config, $coroutineName));
} else { }
[$time, $clients] = $this->get($coroutineName); [$time, $clients] = $this->get($coroutineName);
if ($clients === null) { if ($clients === null) {
return $this->getByChannel($coroutineName, $config); return $this->saveClient($coroutineName, $this->newClient($config, $coroutineName));
}
} }
return $this->saveClient($coroutineName, $clients); return $this->saveClient($coroutineName, $clients);
} }