fix: 修复 Redis SCAN cursor 类型问题并优化缓存清除日志

- CacheService.delete_pattern 中 cursor 可能为 int 或 str,统一转为 int 比较
- 模型缓存清除时区分有/无缓存的日志级别(info/debug)
This commit is contained in:
fawney19
2026-01-23 16:23:17 +08:00
parent 6f597a5f54
commit f45fd06fb0
2 changed files with 7 additions and 3 deletions

View File

@@ -125,7 +125,7 @@ class CacheService:
# 使用 SCAN 遍历匹配的键
deleted_count = 0
cursor = 0
cursor: int = 0
while True:
cursor, keys = await redis.scan(cursor, match=pattern, count=batch_size)
if keys:
@@ -134,7 +134,8 @@ class CacheService:
batch = keys[i : i + batch_size]
await redis.delete(*batch)
deleted_count += len(batch)
if cursor == 0:
# cursor 可能是 int 或 str取决于 decode_responses 配置),统一转为 int 比较
if int(cursor) == 0:
break
if deleted_count > 0: