Backend Development
Step 16 / 2090 min

Redis & Caching

Reliability

Explanation

Redis stores hot data in memory so repeated reads do not hit the database every time.

Code example

typescript
const cached = await redis.get("skills:list");
if (cached) return JSON.parse(cached);
const skills = await prisma.skill.findMany();
await redis.set("skills:list", JSON.stringify(skills), "EX", 60);
return skills;

Helpful resources

Exercise

Cache a GET list endpoint in Redis for 60 seconds and invalidate it after POST.