855 协议版本-调整完毕内容
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import logging
|
||||
|
||||
from loguru import logger
|
||||
import mysql.connector
|
||||
import redis
|
||||
|
||||
@@ -35,7 +36,7 @@ class DBConnectionManager:
|
||||
mysql_config: MySQL配置
|
||||
redis_config: Redis配置
|
||||
"""
|
||||
self.logger = logging.getLogger("DBConnectionManager")
|
||||
self.LOG = logger
|
||||
self.mysql_pool = None
|
||||
self.redis_pool = None
|
||||
|
||||
@@ -55,7 +56,7 @@ class DBConnectionManager:
|
||||
"""
|
||||
try:
|
||||
if not config:
|
||||
self.logger.warning("MySQL配置为空,跳过初始化")
|
||||
self.LOG.warning("MySQL配置为空,跳过初始化")
|
||||
return
|
||||
|
||||
# 准备连接池配置
|
||||
@@ -74,9 +75,9 @@ class DBConnectionManager:
|
||||
|
||||
# 创建连接池
|
||||
self.mysql_pool = mysql.connector.pooling.MySQLConnectionPool(**pool_config)
|
||||
self.logger.info("MySQL连接池初始化成功")
|
||||
self.LOG.info("MySQL连接池初始化成功")
|
||||
except Exception as e:
|
||||
self.logger.error(f"MySQL连接池初始化失败: {e}")
|
||||
self.LOG.error(f"MySQL连接池初始化失败: {e}")
|
||||
self.mysql_pool = None
|
||||
|
||||
def init_redis_pool(self, config):
|
||||
@@ -87,7 +88,7 @@ class DBConnectionManager:
|
||||
"""
|
||||
try:
|
||||
if not config:
|
||||
self.logger.warning("Redis配置为空,跳过初始化")
|
||||
self.LOG.warning("Redis配置为空,跳过初始化")
|
||||
return
|
||||
|
||||
self.redis_pool = redis.ConnectionPool(
|
||||
@@ -98,9 +99,9 @@ class DBConnectionManager:
|
||||
decode_responses=config.get('decode_responses', True),
|
||||
max_connections=config.get('max_connections', 10)
|
||||
)
|
||||
self.logger.info("Redis连接池初始化成功")
|
||||
self.LOG.info("Redis连接池初始化成功")
|
||||
except Exception as e:
|
||||
self.logger.error(f"Redis连接池初始化失败: {e}")
|
||||
self.LOG.error(f"Redis连接池初始化失败: {e}")
|
||||
self.redis_pool = None
|
||||
|
||||
def get_mysql_connection(self):
|
||||
|
||||
Reference in New Issue
Block a user