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\Exception\RedisConnectException;
use Kiri\Pool\Pool; use Kiri\Pool\Pool;
use RedisException; use RedisException;
use wchat\common\Result;
use function config; use function config;
/** /**
@@ -133,7 +134,7 @@ SCRIPT;
*/ */
public function destroy(): void 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)); return trigger_print_error(throwable($throwable));
} finally { } finally {
if ($client->ping('h') == 'h') { 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 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 protected function pool(): Pool
{ {
$pool = Kiri::getPool(); $pool = Kiri::getPool();
if (!$pool->hasChannel('mysql.' . $this->host)) { if (!$pool->hasChannel($this->getName())) {
$pool->created('mysql.' . $this->host, $this->pool['max'], [$this, 'connect']); $pool->created($this->getName(), $this->pool['max'], [$this, 'connect']);
} }
return $pool; return $pool;
} }
/**
* @return string
*/
private function getName(): string
{
return 'redis.' . $this->host;
}
/** /**
* @return \Redis * @return \Redis
* @throws * @throws