-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcache.py
More file actions
24 lines (20 loc) · 748 Bytes
/
cache.py
File metadata and controls
24 lines (20 loc) · 748 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
import redis
from config import config
REDIS_HOST = config.REDIS_HOST
REDIS_PORT = config.REDIS_PORT
REDIS_DB = config.REDIS_DB
CACHE_EXPIRATION = config.CACHE_EXPIRATION
redis_client = redis.Redis(host=REDIS_HOST, port=REDIS_PORT, db=REDIS_DB, decode_responses=True)
def get_cached_weather(key: str):
"""Retrieve weather data from Redis cache."""
try:
return redis_client.get(key)
except redis.RedisError as e:
print(f"Redis error: {e}") # Debug logging
return None
def set_cached_weather(key: str, data: str):
"""Store weather data in Redis cache."""
try:
redis_client.setex(key, CACHE_EXPIRATION, data)
except redis.RedisError as e:
print(f"Redis error: {e}") # Debug logging