aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Leon Sandøy <[email protected]>2020-05-26 18:47:16 +0200
committerGravatar Leon Sandøy <[email protected]>2020-05-26 19:07:14 +0200
commit723c1d3337b0a59401f1d3fc50a123f0314a5d3e (patch)
tree28447d40c345944b704dbcfb638ea7035db226fa
parentTurn log.exception into log.error (diff)
Fix edge case where pop might not delete.
If you passed a key for a value that was the same as your optional, it would just return it but not delete it. This edge case isn't worth it, so I'm just removing that condition and letting the extra API call fly.
-rw-r--r--bot/utils/redis_cache.py12
1 files changed, 6 insertions, 6 deletions
diff --git a/bot/utils/redis_cache.py b/bot/utils/redis_cache.py
index da78f1431..dd20b5842 100644
--- a/bot/utils/redis_cache.py
+++ b/bot/utils/redis_cache.py
@@ -222,7 +222,7 @@ class RedisCache:
log.trace(f"Setting {key} to {value}.")
await self._redis.hset(self._namespace, key, value)
- async def get(self, key: RedisType, default: Optional[RedisType] = None) -> RedisType:
+ async def get(self, key: RedisType, default: Optional[RedisType] = None) -> Optional[RedisType]:
"""Get an item from the Redis cache."""
await self._validate_cache()
key = self._to_typestring(key)
@@ -311,11 +311,11 @@ class RedisCache:
log.trace(f"Attempting to pop {key}.")
value = await self.get(key, default)
- # No need to try to delete something that doesn't exist,
- # that's just a superfluous API call.
- if value != default:
- log.trace(f"Key {key} exists, deleting it from the cache.")
- await self.delete(key)
+ log.trace(
+ f"Attempting to delete item with key '{key}' from the cache. "
+ "If this key doesn't exist, nothing will happen."
+ )
+ await self.delete(key)
return value