mirror of
https://github.com/PaiGramTeam/PaiGram.git
synced 2024-11-23 00:01:45 +00:00
8f424bf0d4
♻️ 重构插件系统 ⚙️ 重写插件 🎨 改进代码结构 📝 完善文档 Co-authored-by: zhxy-CN <admin@owo.cab> Co-authored-by: 洛水居室 <luoshuijs@outlook.com> Co-authored-by: xtaodada <xtao@xtaolink.cn> Co-authored-by: Li Chuangbo <im@chuangbo.li>
23 lines
783 B
Python
23 lines
783 B
Python
from typing import List
|
|
|
|
from core.base.redisdb import RedisDB
|
|
|
|
|
|
class GameCache:
|
|
def __init__(self, redis: RedisDB, qname: str, ttl: int = 3600):
|
|
self.client = redis.client
|
|
self.qname = qname
|
|
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
|