📦
Lesson 1 of 4 · Caching
The speed trick every app needs
Run an expensive operation once — serve the result instantly forever after.
🔴 Cache miss — database was called
2005ms
Database response time
<1ms
What Redis will take next time

The key didn't exist in Redis, so we waited for the (simulated) database. That took 2005ms. The result is now stored in Redis for 30 seconds.

What just happened in Redis
💻 Redis commands — step by step
redis> GET demo:expensive_query
→ (nil) ← key doesn't exist, this is a cache miss
Redis checked for the key. It wasn't there.
So the app had to go to the (slow) database instead.
redis> SET demo:expensive_query "user_count=4821, revenue=98234.50, fetched_at=2026-05-13T16:49:00.780Z" EX 30
→ OK
Now we store the result with a 30-second timer.
EX 30 = "delete this key automatically after 30 seconds".
Every request for the next 30s will get this from Redis instead of the database.
💡 Now try the cache hit

Refresh this page → The next request will be served by Redis in under 1ms. You'll see the timing jump from ~2005ms to <1ms. That's caching.

Now (miss)
Database
Hit the
Database 💾
Store in
Redis ⚡

Next time (hit)
Redis ⚡
Response
<1ms
Database
skipped