mirror of
https://github.com/PaiGramTeam/PaiGram.git
synced 2024-11-26 10:16:32 +00:00
031198b08d
Signed-off-by: Lei Shi <me@leishi.io> Co-authored-by: 洛水居室 <luoshuijs@outlook.com> Co-authored-by: CHxCOOH <chxcooh@googlemail.com> Co-authored-by: xtaodada <xtao@xtaolink.cn> Co-authored-by: Nahida <53059854+NahidaBuer@users.noreply.github.com> Co-authored-by: omg-xtao <100690902+omg-xtao@users.noreply.github.com>
29 lines
820 B
Python
29 lines
820 B
Python
from typing import Optional
|
|
|
|
from core.dependence.redisdb import RedisDB
|
|
|
|
__all__ = [
|
|
"GCSimCache",
|
|
]
|
|
|
|
|
|
class GCSimCache:
|
|
qname: str = "gcsim:"
|
|
|
|
def __init__(self, redis: RedisDB, ttl: int = 24 * 60 * 60):
|
|
self.client = redis.client
|
|
self.ttl = ttl
|
|
|
|
def get_key(self, player_id: str, script_hash: int) -> str:
|
|
return f"{self.qname}:{player_id}:{script_hash}"
|
|
|
|
async def set_cache(self, player_id: str, script_hash: int, file_id: str) -> None:
|
|
key = self.get_key(player_id, script_hash)
|
|
await self.client.set(key, file_id, ex=self.ttl)
|
|
|
|
async def get_cache(self, player_id: str, script_hash: int) -> Optional[str]:
|
|
key = self.get_key(player_id, script_hash)
|
|
data = await self.client.get(key)
|
|
if data:
|
|
return data.decode()
|