mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 17:30:23 +08:00
fix: 修复 Redis SCAN cursor 类型问题并优化缓存清除日志
- CacheService.delete_pattern 中 cursor 可能为 int 或 str,统一转为 int 比较 - 模型缓存清除时区分有/无缓存的日志级别(info/debug)
This commit is contained in:
@@ -73,7 +73,10 @@ async def invalidate_models_list_cache() -> None:
|
|||||||
try:
|
try:
|
||||||
# 使用通配符删除所有 models:list:* 缓存(包括多格式组合的 key)
|
# 使用通配符删除所有 models:list:* 缓存(包括多格式组合的 key)
|
||||||
deleted = await CacheService.delete_pattern(f"{_CACHE_KEY_PREFIX}:*")
|
deleted = await CacheService.delete_pattern(f"{_CACHE_KEY_PREFIX}:*")
|
||||||
logger.debug(f"[ModelsService] 已清除 {deleted} 个 {_CACHE_KEY_PREFIX} 缓存")
|
if deleted > 0:
|
||||||
|
logger.info(f"[ModelsService] 已清除 {deleted} 个 {_CACHE_KEY_PREFIX} 缓存")
|
||||||
|
else:
|
||||||
|
logger.debug(f"[ModelsService] 无 {_CACHE_KEY_PREFIX} 缓存需要清除")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"[ModelsService] 清除缓存失败: {e}")
|
logger.warning(f"[ModelsService] 清除缓存失败: {e}")
|
||||||
|
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ class CacheService:
|
|||||||
|
|
||||||
# 使用 SCAN 遍历匹配的键
|
# 使用 SCAN 遍历匹配的键
|
||||||
deleted_count = 0
|
deleted_count = 0
|
||||||
cursor = 0
|
cursor: int = 0
|
||||||
while True:
|
while True:
|
||||||
cursor, keys = await redis.scan(cursor, match=pattern, count=batch_size)
|
cursor, keys = await redis.scan(cursor, match=pattern, count=batch_size)
|
||||||
if keys:
|
if keys:
|
||||||
@@ -134,7 +134,8 @@ class CacheService:
|
|||||||
batch = keys[i : i + batch_size]
|
batch = keys[i : i + batch_size]
|
||||||
await redis.delete(*batch)
|
await redis.delete(*batch)
|
||||||
deleted_count += len(batch)
|
deleted_count += len(batch)
|
||||||
if cursor == 0:
|
# cursor 可能是 int 或 str(取决于 decode_responses 配置),统一转为 int 比较
|
||||||
|
if int(cursor) == 0:
|
||||||
break
|
break
|
||||||
|
|
||||||
if deleted_count > 0:
|
if deleted_count > 0:
|
||||||
|
|||||||
Reference in New Issue
Block a user