Spaces:
Runtime error

File size: 380 Bytes
747ecf5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import redis
import os
from dotenv import load_dotenv

load_dotenv()

REDIS_URL = os.getenv("REDIS_URL")
if REDIS_URL:
    cache = redis.from_url(REDIS_URL)
else:
    cache = None

def get_from_cache(key: str):
    if cache:
        return cache.get(key)
    return None

def set_in_cache(key: str, value: str, ttl: int = 3600):
    if cache:
        cache.set(key, value, ex=ttl)