Spaces:
Runtime error
Runtime error
Download cache.py from LeeHan23/nutribot-api: direct link, hf CLI and curl.
- Browser
- Download file 380 Bytes
-
https://huggingface.co/spaces/LeeHan23/nutribot-api/resolve/main/cache.py
- Command line
-
hf download hf://spaces/LeeHan23/nutribot-api/cache.py
-
curl -L -o cache.py https://huggingface.co/spaces/LeeHan23/nutribot-api/resolve/main/cache.py
380 Bytes
| 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) |