On this page
article
Redis Cache
Cache API responses in Redis.
Category: redis
Problem
Cache API responses in Redis.
Solution
r.setex(f"user:{id}", 3600, json.dumps(data))
cached = r.get(f"user:{id}")
Notes
- Adapt variable names and paths to your project
- Add error handling for production use
- See related chapters in the Learning Path