aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bot/exts/info/doc/_redis_cache.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/bot/exts/info/doc/_redis_cache.py b/bot/exts/info/doc/_redis_cache.py
index 2a2f5e4b4..ef9abd981 100644
--- a/bot/exts/info/doc/_redis_cache.py
+++ b/bot/exts/info/doc/_redis_cache.py
@@ -8,6 +8,7 @@ from typing import Optional, TYPE_CHECKING
from async_rediscache.types.base import RedisObject
from bot.log import get_logger
+from bot.utils.lock import lock
if TYPE_CHECKING:
from ._cog import DocItem
@@ -17,6 +18,12 @@ WEEK_SECONDS = int(datetime.timedelta(weeks=1).total_seconds())
log = get_logger(__name__)
+def serialize_resource_id_from_doc_item(bound_args: dict) -> str:
+ """Return the redis_key of the DocItem `item` from the bound args of DocRedisCache.set."""
+ item: DocItem = bound_args["item"]
+ return f"doc:{item_key(item)}"
+
+
class DocRedisCache(RedisObject):
"""Interface for redis functionality needed by the Doc cog."""
@@ -24,6 +31,7 @@ class DocRedisCache(RedisObject):
super().__init__(*args, **kwargs)
self._set_expires = dict[str, float]()
+ @lock("DocRedisCache.set", serialize_resource_id_from_doc_item, wait=True)
async def set(self, item: DocItem, value: str) -> None:
"""
Set the Markdown `value` for the symbol `item`.