diff --git a/src/ZM/Event/Listener/WorkerEventListener.php b/src/ZM/Event/Listener/WorkerEventListener.php index fda3c11d..65f82ebd 100644 --- a/src/ZM/Event/Listener/WorkerEventListener.php +++ b/src/ZM/Event/Listener/WorkerEventListener.php @@ -262,30 +262,7 @@ class WorkerEventListener */ private function initConnectionPool(): void { - // 清空 MySQL 的连接池 - foreach (DBPool::getAllPools() as $name => $pool) { - DBPool::destroyPool($name); - } - // 清空 Redis 连接池 - foreach (RedisPool::getAllPools() as $name => $pool) { - RedisPool::destroyPool($name); - } - - // 读取 MySQL/PostgresSQL/SQLite 配置文件并创建连接池 - $conf = config('global.database'); - // 如果有多个数据库连接,则遍历 - foreach ($conf as $name => $conn_conf) { - if (($conn_conf['enable'] ?? true) !== false) { - DBPool::create($name, $conn_conf); - } - } - - // 读取 Redis 配置文件并创建池 - $redis_conf = config('global.redis'); - foreach ($redis_conf as $name => $conn_conf) { - if (($conn_conf['enable'] ?? true) !== false) { - RedisPool::create($name, $conn_conf); - } - } + DBPool::resetPools(); + RedisPool::resetPools(); } } diff --git a/src/ZM/Framework.php b/src/ZM/Framework.php index bd8deba1..0d8ccb00 100644 --- a/src/ZM/Framework.php +++ b/src/ZM/Framework.php @@ -50,7 +50,7 @@ class Framework public const VERSION_ID = 719; /** @var string 版本名称 */ - public const VERSION = '3.1.13'; + public const VERSION = '3.1.14'; /** * @var RuntimePreferences 运行时偏好(环境信息&参数) diff --git a/src/ZM/Store/Database/DBPool.php b/src/ZM/Store/Database/DBPool.php index 9fbd0796..8e17fd44 100644 --- a/src/ZM/Store/Database/DBPool.php +++ b/src/ZM/Store/Database/DBPool.php @@ -21,6 +21,28 @@ class DBPool */ private static array $pools = []; + /** + * 重新初始化连接池,有时候连不上某个对象时候可以使用,也可以定期调用释放链接 + * + * @throws DBException + */ + public static function resetPools(): void + { + // 清空 MySQL 的连接池 + foreach (DBPool::getAllPools() as $name => $pool) { + DBPool::destroyPool($name); + } + + // 读取 MySQL/PostgresSQL/SQLite 配置文件并创建连接池 + $conf = config('global.database'); + // 如果有多个数据库连接,则遍历 + foreach ($conf as $name => $conn_conf) { + if (($conn_conf['enable'] ?? true) !== false) { + DBPool::create($name, $conn_conf); + } + } + } + /** * 通过配置文件创建一个 MySQL 连接池 * diff --git a/src/ZM/Store/KV/Redis/RedisPool.php b/src/ZM/Store/KV/Redis/RedisPool.php index f356cd02..855265f9 100644 --- a/src/ZM/Store/KV/Redis/RedisPool.php +++ b/src/ZM/Store/KV/Redis/RedisPool.php @@ -18,6 +18,27 @@ class RedisPool */ public static array $pools = []; + /** + * 重新初始化连接池,有时候连不上某个对象时候可以使用,也可以定期调用释放链接 + * + * @throws RedisException + */ + public static function resetPools(): void + { + // 清空 Redis 连接池 + foreach (self::getAllPools() as $name => $pool) { + self::destroyPool($name); + } + + // 读取 Redis 配置文件并创建池 + $redis_conf = config('global.redis'); + foreach ($redis_conf as $name => $conn_conf) { + if (($conn_conf['enable'] ?? true) !== false) { + self::create($name, $conn_conf); + } + } + } + /** * @throws RedisException */