feat: +redis

This commit is contained in:
莘权 马 2023-09-04 14:03:20 +08:00
parent 0ffd3db947
commit cce76df319
2 changed files with 37 additions and 0 deletions

View file

@ -196,3 +196,19 @@ class Redis:
RedisManager.init_redis_conn(host=host, port=port, password=pwd, db=db)
except Exception as e:
logger.warning(f"Redis initialization has failed:{e}")
def is_valid(self):
return RedisManager.is_valid()
async def get(self, key: str) -> str:
if not self.is_valid() or not key:
return None
v = await RedisManager.get_with_cache_info(redis_cache_info=RedisCacheInfo(key=key))
return v
async def set(self, key: str, data: str, timeout_sec: int):
if not self.is_valid() or not key:
return
await RedisManager.set_with_cache_info(
redis_cache_info=RedisCacheInfo(key=key, timeout=timeout_sec), value=data
)