Skip to content

Commit 26c5377

Browse files
committed
Fixed the delete keys by pattern
1 parent 2457ca5 commit 26c5377

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/app/core/utils/cache.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,13 @@ async def _delete_keys_by_pattern(pattern: str) -> None:
171171
- Be cautious with patterns that could match a large number of keys, as deleting
172172
many keys simultaneously may impact the performance of the Redis server.
173173
"""
174-
if client is None:
175-
raise MissingClientError
176-
177-
cursor = -1
178-
while cursor != 0:
174+
cursor = 0 # Make sure cursor starts at 0
175+
while True:
179176
cursor, keys = await client.scan(cursor, match=pattern, count=100)
180177
if keys:
181178
await client.delete(*keys)
179+
if cursor == 0: # cursor returns to 0 when scan is complete
180+
break
182181

183182

184183
def cache(

0 commit comments

Comments
 (0)