fix(cache): increase Redis pool defaults

This commit is contained in:
jxxghp
2026-09-26 15:06:27 +08:00
parent 3621795e76
commit 807a90fab7
2 changed files with 12 additions and 4 deletions

View File

@@ -329,10 +329,10 @@ class ConfigModel(BaseModel):
CACHE_BACKEND_URL: Optional[str] = "redis://localhost:6379"
# Redis 缓存最大内存限制,未配置时,如开启大内存模式时为 "1024mb",未开启时为 "256mb"
CACHE_REDIS_MAXMEMORY: Optional[str] = None
# Redis 连接池最大连接数
CACHE_REDIS_MAX_CONNECTIONS: int = 256
# Redis 单个连接池最大连接数;异步连接池按事件循环分别应用该上限
CACHE_REDIS_MAX_CONNECTIONS: int = 512
# Redis 连接池耗尽时等待可用连接的时间(秒)
CACHE_REDIS_POOL_TIMEOUT: int = 3
CACHE_REDIS_POOL_TIMEOUT: int = 10
# 全局图片缓存,将媒体图片缓存到本地
GLOBAL_IMAGE_CACHE: bool = False
# 全局图片缓存保留天数

View File

@@ -23,7 +23,7 @@ from app.runtime.cache import (
TTLCache,
cached,
)
from app.runtime.config import settings
from app.runtime.config import ConfigModel, settings
def test_file_backend_items_keep_relative_keys_and_bytes(tmp_path):
@@ -979,6 +979,14 @@ def test_redis_helpers_watch_pool_settings():
assert "BIG_MEMORY_MODE" in AsyncRedisHelper.CONFIG_WATCH
def test_redis_pool_defaults_cover_startup_concurrency():
"""Redis 默认连接池应为启动期并发读写留出容量和等待时间。"""
config = ConfigModel()
assert config.CACHE_REDIS_MAX_CONNECTIONS == 512
assert config.CACHE_REDIS_POOL_TIMEOUT == 10
def test_async_file_backend_missing_region_has_no_items(tmp_path):
"""
异步文件缓存缺失区域时应返回空迭代,而不是伪造空 key。