# praisonai/cache/redis_cache.py
from praisonaiagents.cache.protocols import CacheProtocol
class RedisCache: # Implements CacheProtocol via duck typing
"""Redis implementation - lives in wrapper, NOT core."""
def __init__(self, url: str):
import redis # Lazy import - only when used
self.client = redis.from_url(url)
def get(self, key: str):
value = self.client.get(key)
if value:
import json
return json.loads(value)
return None
def set(self, key: str, value, ttl=None):
import json
if ttl:
self.client.setex(key, ttl, json.dumps(value))
else:
self.client.set(key, json.dumps(value))