diff --git a/pyproject.toml b/pyproject.toml index 9bde91e29..ae1304aa7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -83,7 +83,8 @@ dependencies = [ "fastmcp>=2.13.0", "mofox-wire", "jinja2>=3.1.0", - "psycopg2-binary" + "psycopg2-binary", + "redis>=7.1.0", ] [[tool.uv.index]] diff --git a/src/common/database/optimization/__init__.py b/src/common/database/optimization/__init__.py index fbbf10375..4a6e43031 100644 --- a/src/common/database/optimization/__init__.py +++ b/src/common/database/optimization/__init__.py @@ -33,6 +33,7 @@ from .preloader import ( get_preloader, record_preload_access, ) +from .redis_cache import RedisCache, close_redis_cache, get_redis_cache __all__ = [ "AccessPattern", @@ -52,12 +53,16 @@ __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 81ce1f5ed..e22797af1 100644 --- a/src/common/database/optimization/cache_manager.py +++ b/src/common/database/optimization/cache_manager.py @@ -887,12 +887,7 @@ async def _create_redis_cache(db_config: Any) -> CacheBackend: Raises: RuntimeError: Redis 连接失败时抛出异常 """ - 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 + from src.common.database.optimization.redis_cache import RedisCache logger.info( f"创建 Redis 缓存: {db_config.redis_host}:{db_config.redis_port}/{db_config.redis_db}, "