aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Leon Sandøy <[email protected]>2020-05-17 00:10:29 +0200
committerGravatar Leon Sandøy <[email protected]>2020-05-17 00:10:29 +0200
commit9eeee1ce303b7ebac4fa9db37193921d052d0f8d (patch)
treee3d0e5724087053e10e6dc40ae70bad6df84a460
parentcopy should dictify the .items(), not just keys. (diff)
Implements .clear with hash deletion.
This would've been implemented by MutableMapping, but that implementation is O(n) instead of O(1) since it just iterates the entire hash and does HDEL. Feels wasteful.
-rw-r--r--bot/utils/redis_dict.py (renamed from bot/utils/redis.py)4
1 files changed, 4 insertions, 0 deletions
diff --git a/bot/utils/redis.py b/bot/utils/redis_dict.py
index 470de47b7..b2fd7d2e9 100644
--- a/bot/utils/redis.py
+++ b/bot/utils/redis_dict.py
@@ -78,3 +78,7 @@ class RedisDict(MutableMapping):
def copy(self) -> Dict:
"""Convert to dict and return."""
return dict(self.items())
+
+ def clear(self) -> None:
+ """Deletes the entire hash from the Redis cache."""
+ self._redis.delete(self._namespace)