a
This commit is contained in:
parent
ba8396827a
commit
32a0bf3b3a
|
|
@ -90,6 +90,18 @@ logger = logging.getLogger(__name__)
|
|||
logger.info(f"日志系统已初始化,日志文件: {log_file}")
|
||||
logger.info(f"日志级别: {os.getenv('LOG_LEVEL', 'INFO')}")
|
||||
|
||||
# 检查 aioredis 是否可用
|
||||
try:
|
||||
import aioredis
|
||||
logger.info(f"✓ aioredis 已安装 (版本: {aioredis.__version__ if hasattr(aioredis, '__version__') else '未知'})")
|
||||
except ImportError as e:
|
||||
import sys
|
||||
logger.warning("⚠ aioredis 未安装,Redis/Valkey 缓存将不可用")
|
||||
logger.warning(f" Python 路径: {sys.executable}")
|
||||
logger.warning(f" 导入错误: {e}")
|
||||
logger.warning(f" 提示: 请运行 'pip install aioredis==2.0.1' 安装 aioredis")
|
||||
logger.warning(f" 或者运行 'pip install -r backend/requirements.txt' 安装所有依赖")
|
||||
|
||||
app = FastAPI(
|
||||
title="Auto Trade System API",
|
||||
version="1.0.0",
|
||||
|
|
|
|||
|
|
@ -10,9 +10,15 @@ try:
|
|||
import aioredis
|
||||
from aioredis import Redis
|
||||
AIOREDIS_AVAILABLE = True
|
||||
except ImportError:
|
||||
except ImportError as e:
|
||||
AIOREDIS_AVAILABLE = False
|
||||
Redis = None
|
||||
import sys
|
||||
import os
|
||||
# 保存导入错误信息,用于诊断
|
||||
_import_error = str(e)
|
||||
_python_path = sys.executable
|
||||
_python_version = sys.version
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
|
@ -48,7 +54,13 @@ class RedisCache:
|
|||
async def connect(self):
|
||||
"""连接 Redis"""
|
||||
if not AIOREDIS_AVAILABLE:
|
||||
import sys
|
||||
import os
|
||||
logger.warning("aioredis 未安装,将使用内存缓存")
|
||||
logger.debug(f" Python 路径: {sys.executable}")
|
||||
logger.debug(f" Python 版本: {sys.version.split()[0]}")
|
||||
logger.debug(f" 导入错误: {_import_error if '_import_error' in globals() else '未知'}")
|
||||
logger.debug(f" 提示: 请运行 'pip install aioredis==2.0.1' 安装 aioredis")
|
||||
self.redis = None
|
||||
self._connected = False
|
||||
return
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user