From da1f6c7c939c4aca7221271f98cde9a795232ef3 Mon Sep 17 00:00:00 2001 From: Kartik Ohri Date: Fri, 27 May 2022 21:27:55 +0530 Subject: [PATCH] Fix key expiry when using sadd We are passing prepared_name (namespace appended) to BU cache's expire method which again appends the namespace. Due to this, the following commands get executed: SADD "CB-prod:Review:ws_cache_de0eedbf-e2d9-3a64-8e3e-51d68994cee3" "\xd9\x92list_entity_id=de0eedbf-e2d9-3a64-8e3e-51d68994cee3_user_id=None_sort=published_on_sort_order=None_limit=1_offset=0_language=None_review_type=None" PEXPIRE "CB-prod:Review:CB-prod:Review:ws_cache_de0eedbf-e2d9-3a64-8e3e-51d68994cee3" "1800000" As we can see, the pexpired key is wrong. Therefore, the sadd'ed keys live with infinite TTL in redis. Fix this by passing the un-prepared name to expire method. --- brainzutils/cache.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brainzutils/cache.py b/brainzutils/cache.py index 04daa16..5ec0a90 100644 --- a/brainzutils/cache.py +++ b/brainzutils/cache.py @@ -337,7 +337,7 @@ def sadd(name, keys, expirein, encode=True, namespace=None): keys = {_encode_val(key) for key in keys} result = _r.sadd(prepared_name, *keys) - expire(prepared_name, expirein, namespace) + expire(name, expirein, namespace) return result