redis

Configure async Redis caching with get, set, and delete operations in FastAPI projects.

Updated Sep 13, 2026
One-click install
npx skills add https://github.com/abdulazeezoj/monovella-poc --skill redis-abdulazeezoj
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: redis
Source: https://github.com/abdulazeezoj/monovella-poc/tree/main/.agents/skills/redis
Command: npx skills add https://github.com/abdulazeezoj/monovella-poc --skill redis-abdulazeezoj

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires redis, and includes references (resource) components.

What problem does it solve? Adding response caching to an async FastAPI project requires correctly wiring a Redis client, choosing TTLs, and—most importantly—invalidating stale keys on writes, which is where most caching bugs come from. This Skill documents the project's module-level redis_client and the exact conventions for using it without blocking the event loop or serving stale data. ## Core Features & Use Cases - Module-level async client: A single redis.asyncio.Redis instance in core/redis.py, built from REDIS_URL with decode_responses=True, safe to import anywhere. - Caching conventions: get/set with ex TTL, delete for invalidation, JSON serialization handled manually, and a <resource>:<qualifier> key naming pattern. - End-to-end guide: A before/after walkthrough that adds caching to the GET /items/ endpoint and invalidates the key in the create handler. - Use Case: You cache an expensive list endpoint, then add a write handler—this Skill ensures you also add the matching redis_client.delete(...) call so users never see stale data. ## Quick Start Ask the AI to add Redis caching with a 60-second TTL to the items list endpoint and invalidate the cache key on every write.

Frequently Asked Questions about redis

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add Redis caching to a FastAPI endpoint?

Import the module-level redis_client, call await redis_client.get(key) before the real lookup, and on a miss store the result with await redis_client.set(key, json.dumps(payload), ex=60). The handler must become async def once it awaits the client.

How do I invalidate a Redis cache key after a write?

Call await redis_client.delete(key) in every create, update, or delete handler that modifies the cached resource. Delete is a no-op if the key does not exist, so it is safe to call unconditionally before returning.

Should I use redis or redis.asyncio with FastAPI?

Use redis.asyncio inside async FastAPI handlers. The synchronous redis.Redis client blocks the event loop during each call, stalling every in-flight request, and low local traffic hides this until real concurrent load arrives.

Why is my FastAPI app serving stale data after a write?

The cached response was not invalidated when the underlying data changed, so it stays stale until its TTL expires. Add an explicit redis_client.delete call for the affected key in every write handler; a TTL is only a safety net.

Does redis.asyncio require a separate package or hiredis?

No. redis.asyncio ships inside the standard redis package (redis>=5.2.0), so nothing extra is installed for async usage. This project uses the plain dependency without the hiredis extra.