From 31867d3c6c5b50af6552d474a1356fbd9ed36af9 Mon Sep 17 00:00:00 2001 From: Untone Date: Fri, 27 Sep 2024 10:18:08 +0300 Subject: [PATCH] ex-support --- services/redis.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/services/redis.py b/services/redis.py index 8cd3367c..5db49c7a 100644 --- a/services/redis.py +++ b/services/redis.py @@ -57,8 +57,17 @@ class RedisService: return await self._client.publish(channel, data) - async def set(self, key, data): - await self.execute("set", key, data) + async def set(self, key, data, ex=None): + # Prepare the command arguments + args = [key, data] + + # If an expiration time is provided, add it to the arguments + if ex is not None: + args.append("EX") + args.append(ex) + + # Execute the command with the provided arguments + await self.execute("set", *args) async def get(self, key): return await self.execute("get", key)