This commit is contained in:
2024-05-01 02:06:14 +08:00
parent c7e0cd4948
commit 976f67a838
+15 -5
View File
@@ -14,6 +14,7 @@ use Kiri;
use Kiri\Exception\RedisConnectException;
use Kiri\Pool\Pool;
use RedisException;
use wchat\common\Result;
use function config;
/**
@@ -133,7 +134,7 @@ SCRIPT;
*/
public function destroy(): void
{
$this->pool()->close('mysql.' . $this->host);
$this->pool()->close($this->getName());
}
@@ -152,7 +153,7 @@ SCRIPT;
return trigger_print_error(throwable($throwable));
} finally {
if ($client->ping('h') == 'h') {
$this->pool()->push('mysql.' . $this->host, $client);
$this->pool()->push($this->getName(), $client);
}
}
}
@@ -164,7 +165,7 @@ SCRIPT;
*/
private function getClient(): \Redis
{
return $this->pool()->get('mysql.' . $this->host);
return $this->pool()->get($this->getName());
}
@@ -175,13 +176,22 @@ SCRIPT;
protected function pool(): Pool
{
$pool = Kiri::getPool();
if (!$pool->hasChannel('mysql.' . $this->host)) {
$pool->created('mysql.' . $this->host, $this->pool['max'], [$this, 'connect']);
if (!$pool->hasChannel($this->getName())) {
$pool->created($this->getName(), $this->pool['max'], [$this, 'connect']);
}
return $pool;
}
/**
* @return string
*/
private function getName(): string
{
return 'redis.' . $this->host;
}
/**
* @return \Redis
* @throws