2022-07-26 10:07:31 +00:00
|
|
|
from typing import List
|
|
|
|
|
2022-09-08 01:08:37 +00:00
|
|
|
from core.base.redisdb import RedisDB
|
2022-07-26 10:07:31 +00:00
|
|
|
|
|
|
|
|
2022-08-31 06:48:15 +00:00
|
|
|
class GameCache:
|
|
|
|
def __init__(self, redis: RedisDB, qname: str, ttl: int = 3600):
|
2022-07-26 10:07:31 +00:00
|
|
|
self.client = redis.client
|
2022-08-31 06:48:15 +00:00
|
|
|
self.qname = qname
|
2022-07-26 10:07:31 +00:00
|
|
|
self.ttl = ttl
|
|
|
|
|
|
|
|
async def get_url_list(self, character_name: str):
|
|
|
|
qname = f"{self.qname}:{character_name}"
|
|
|
|
return [str(str_data, encoding="utf-8") for str_data in await self.client.lrange(qname, 0, -1)]
|
|
|
|
|
|
|
|
async def set_url_list(self, character_name: str, str_list: List[str]):
|
|
|
|
qname = f"{self.qname}:{character_name}"
|
|
|
|
await self.client.ltrim(qname, 1, 0)
|
|
|
|
await self.client.lpush(qname, *str_list)
|
|
|
|
await self.client.expire(qname, self.ttl)
|
|
|
|
count = await self.client.llen(qname)
|
|
|
|
return count
|