import redis r = redis.Redis(host="localhost", port=6379, password="b5eb4d10f12a5b1f82ab0a581105d5192a0a0b22366934dc", decode_responses=True) to_del = [] n = 0 for k in r.scan_iter("translation:cache:*", count=200): v = r.get(k) if v and ("[翻译失败" in v or "[本条未翻译" in v): to_del.append(k) n += 1 print(f" found {n} bad keys, deleting...") if to_del: r.delete(*to_del) print(f" deleted {len(to_del)}") # 总数 total = sum(1 for _ in r.scan_iter("translation:cache:*", count=200)) print(f" remaining cache keys: {total}")