Fix linting
Browse files- lightrag/kg/redis_impl.py +15 -8
lightrag/kg/redis_impl.py
CHANGED
@@ -86,32 +86,39 @@ class RedisKVStorage(BaseKVStorage):
|
|
86 |
result = {}
|
87 |
pattern = f"{self.namespace}:*"
|
88 |
cursor = 0
|
89 |
-
|
90 |
while True:
|
91 |
-
cursor, keys = await redis.scan(
|
92 |
-
|
|
|
|
|
93 |
if keys:
|
94 |
# Batch get values for these keys
|
95 |
pipe = redis.pipeline()
|
96 |
for key in keys:
|
97 |
pipe.get(key)
|
98 |
values = await pipe.execute()
|
99 |
-
|
100 |
# Check each value for cache_type == "extract"
|
101 |
for key, value in zip(keys, values):
|
102 |
if value:
|
103 |
try:
|
104 |
data = json.loads(value)
|
105 |
-
if
|
|
|
|
|
|
|
106 |
# Extract cache key (remove namespace prefix)
|
107 |
-
cache_key = key.replace(
|
|
|
|
|
108 |
result[cache_key] = data
|
109 |
except json.JSONDecodeError:
|
110 |
continue
|
111 |
-
|
112 |
if cursor == 0:
|
113 |
break
|
114 |
-
|
115 |
return result if result else None
|
116 |
except Exception as e:
|
117 |
logger.error(f"Error scanning Redis for extract cache entries: {e}")
|
|
|
86 |
result = {}
|
87 |
pattern = f"{self.namespace}:*"
|
88 |
cursor = 0
|
89 |
+
|
90 |
while True:
|
91 |
+
cursor, keys = await redis.scan(
|
92 |
+
cursor, match=pattern, count=100
|
93 |
+
)
|
94 |
+
|
95 |
if keys:
|
96 |
# Batch get values for these keys
|
97 |
pipe = redis.pipeline()
|
98 |
for key in keys:
|
99 |
pipe.get(key)
|
100 |
values = await pipe.execute()
|
101 |
+
|
102 |
# Check each value for cache_type == "extract"
|
103 |
for key, value in zip(keys, values):
|
104 |
if value:
|
105 |
try:
|
106 |
data = json.loads(value)
|
107 |
+
if (
|
108 |
+
isinstance(data, dict)
|
109 |
+
and data.get("cache_type") == "extract"
|
110 |
+
):
|
111 |
# Extract cache key (remove namespace prefix)
|
112 |
+
cache_key = key.replace(
|
113 |
+
f"{self.namespace}:", ""
|
114 |
+
)
|
115 |
result[cache_key] = data
|
116 |
except json.JSONDecodeError:
|
117 |
continue
|
118 |
+
|
119 |
if cursor == 0:
|
120 |
break
|
121 |
+
|
122 |
return result if result else None
|
123 |
except Exception as e:
|
124 |
logger.error(f"Error scanning Redis for extract cache entries: {e}")
|