rdune71's picture
Add conversation history display and finalize Redis integration
5420da2
raw
history blame
770 Bytes
import json
import redis
from utils.config import config
# Initialize Redis connection
redis_client = redis.Redis(
host=config.redis_host,
port=config.redis_port,
username=config.redis_username,
password=config.redis_password,
decode_responses=True
)
def save_user_state(user_id: str, state: dict):
"""Save user state to Redis"""
try:
redis_client.hset(f"user:{user_id}", mapping=state)
return True
except Exception as e:
print(f"Error saving user state: {e}")
return False
def load_user_state(user_id: str):
"""Load user state from Redis"""
try:
return redis_client.hgetall(f"user:{user_id}")
except Exception as e:
print(f"Error loading user state: {e}")
return {}