19 lines
517 B
Python
19 lines
517 B
Python
|
from json import dumps, loads
|
||
|
from os import environ
|
||
|
from typing import List, Optional
|
||
|
from pynyaata.cache import CACHE_TIMEOUT
|
||
|
from pynyaata.types import Cache, RemoteFile
|
||
|
from redis import Redis
|
||
|
|
||
|
|
||
|
REDIS_URL = environ.get("REDIS_URL", "")
|
||
|
client = Redis.from_url(REDIS_URL)
|
||
|
|
||
|
|
||
|
class RedisCache(Cache):
|
||
|
def get(self, key: str) -> Optional[List[RemoteFile]]:
|
||
|
return loads(str(client.get(key)))
|
||
|
|
||
|
def set(self, key: str, data: List[RemoteFile]):
|
||
|
return client.set(key, dumps(data), CACHE_TIMEOUT)
|