Skip to content

Commit

Permalink
Fix key expiry when using sadd
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
amCap1712 committed May 27, 2022
1 parent 21cc2f9 commit da1f6c7
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion brainzutils/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit da1f6c7

Please sign in to comment.