Redis Integration
Quick Setup
ENABLE_REDIS=true
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_DB=0
REDIS_PASSWORD=your_password # Optional
REDIS_USERNAME=your_username # Optional
REDIS_MAX_CONNECTIONS=10Using Redis in Controllers
from core.redis_manager import redis_manager
from core.controller import Controller
class SensorController(Controller):
@staticmethod
async def handle_temperature(sensor_id, payload, client):
# Cache sensor data in Redis
cache_key = f"sensor:{sensor_id}:latest"
await redis_manager.set_json(cache_key, payload, ex=3600) # Cache for 1 hour
# Get cached historical data
history_key = f"sensor:{sensor_id}:history"
history = await redis_manager.get_json(history_key) or []
return {"status": "processed", "cached": True}Redis Operations
Benefits
Next Steps
Last updated