Skip to content

Commit

Permalink
Flushed care_static_data prefixed redis keys
Browse files Browse the repository at this point in the history
* Used delete_pattern from django-redis repo to delete keys
  • Loading branch information
JohnLu2004 authored and JohnLu2004 committed Oct 29, 2024
1 parent 69c2b83 commit f6172f9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
11 changes: 11 additions & 0 deletions care/facility/management/commands/load_redis_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ class Command(BaseCommand):
help = "Loads static data to redis"

def handle(self, *args, **options):
try:
deleted_count = cache.delete_pattern("care_static_data*", itersize=25_000)
self.stdout.write(
f"Deleted {deleted_count} keys with prefix 'care_static_data'"
)
except Exception as e:
self.stdout.write(
f"Failed to delete keys with prefix 'care_static_data': {e}"
)
return

if cache.get("redis_index_loading"):
self.stdout.write("Redis Index already loading, skipping")
return
Expand Down
7 changes: 7 additions & 0 deletions care/facility/tasks/redis_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@

@shared_task
def load_redis_index():
try:
deleted_count = cache.delete_pattern("care_static_data*", itersize=25_000)
logger.info("Deleted %s keys with prefix 'care_static_data'", deleted_count)
except Exception as e:
logger.error("Failed to delete keys with prefix 'care_static_data': %s", e)
return

if cache.get("redis_index_loading"):
logger.info("Redis Index already loading, skipping")
return
Expand Down

0 comments on commit f6172f9

Please sign in to comment.