-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcache.py
More file actions
30 lines (22 loc) · 680 Bytes
/
Copy pathcache.py
File metadata and controls
30 lines (22 loc) · 680 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import os
from dotenv import load_dotenv
from redis.asyncio import Redis
from typing import Any
load_dotenv()
REDIS_URL: str = os.getenv("REDIS_URL")
redis: Redis = Redis.from_url(REDIS_URL)
async def get_cache_data(cid: str) -> Any:
try:
return await redis.get(cid)
except Exception as e:
return None
async def set_cache_data(cid: str, data: str | dict | list, es: int) -> None:
try:
await redis.set(cid, value=data, ex=es)
except:
raise ValueError("Something went wrong in saving cache data")
async def delete_cache(cid: str) -> None:
try:
await redis.delete(cid)
except Exception as e:
return None