From f76cf36bae892b426922f4807003b2d5d29741f6 Mon Sep 17 00:00:00 2001 From: Windpicker-owo <3431391539@qq.com> Date: Mon, 8 Dec 2025 20:54:23 +0800 Subject: [PATCH] =?UTF-8?q?fix(redis):=20=E6=B7=BB=E5=8A=A0Redis=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E6=A8=A1=E5=9D=97=E5=AF=BC=E5=85=A5=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/database/optimization/__init__.py | 5 ----- src/common/database/optimization/cache_manager.py | 7 ++++++- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/common/database/optimization/__init__.py b/src/common/database/optimization/__init__.py index 4a6e43031..fbbf10375 100644 --- a/src/common/database/optimization/__init__.py +++ b/src/common/database/optimization/__init__.py @@ -33,7 +33,6 @@ from .preloader import ( get_preloader, record_preload_access, ) -from .redis_cache import RedisCache, close_redis_cache, get_redis_cache __all__ = [ "AccessPattern", @@ -53,16 +52,12 @@ __all__ = [ # Memory Cache "MultiLevelCache", "Priority", - # Redis Cache - "RedisCache", "close_batch_scheduler", "close_cache", "close_preloader", - "close_redis_cache", "get_batch_scheduler", "get_cache", "get_cache_backend_type", "get_preloader", "record_preload_access", - "get_redis_cache" ] diff --git a/src/common/database/optimization/cache_manager.py b/src/common/database/optimization/cache_manager.py index e22797af1..81ce1f5ed 100644 --- a/src/common/database/optimization/cache_manager.py +++ b/src/common/database/optimization/cache_manager.py @@ -887,7 +887,12 @@ async def _create_redis_cache(db_config: Any) -> CacheBackend: Raises: RuntimeError: Redis 连接失败时抛出异常 """ - from src.common.database.optimization.redis_cache import RedisCache + try: + from src.common.database.optimization.redis_cache import RedisCache + except ModuleNotFoundError as exc: + raise RuntimeError( + "Redis 缓存后端需要可选依赖 'redis',请执行 `pip install redis` 或将 cache_backend 配置为 'memory'" + ) from exc logger.info( f"创建 Redis 缓存: {db_config.redis_host}:{db_config.redis_port}/{db_config.redis_db}, "