~/VibeHandbook
$39

Databases

redis.io

Redis

What it is

Think of keeping the notes you need right now on the desk in front of you instead of walking to the filing cabinet for each one — much faster, but the desk clears if the power goes out. Redis works like that desk: it keeps data in fast working memory (RAM, or Random Access Memory) rather than on disk, so reads and writes are extremely fast. It can optionally save to disk too. It works as a key-value store but supports rich data structures like lists, sets, sorted sets, hashes, and streams. It is most often used as a , store, , or rate limiter alongside a primary .

Strengths

  • Sub-millisecond latency thanks to in-memory operation.
  • Versatile structures: strings, hashes, lists, sets, sorted sets, streams.
  • Built-in TTL (Time To Live)/expiry — each entry can auto-delete itself after a set time — makes it ideal for caching and sessions.
  • Atomic operations and Lua scripting for safe counters and locks.
  • Pub/sub and streams support messaging and event pipelines.

Trade-offs

  • Data is bounded by available memory; large datasets get expensive.
  • Persistence is optional and can lose recent writes on crash.
  • Not a replacement for a durable relational store.
  • Clustering adds operational complexity for sharding and failover.

When to use it

Use Redis to cache expensive query results, store sessions, implement rate limiting, manage job queues, build leaderboards, or pass real-time messages. Pair it with a durable database that holds the source of truth.

Vibe coding fit

When directing AI, be explicit that Redis is a cache or auxiliary store, not the system of record. So it should always set a TTL on cached entries. It should also design a clear key-naming scheme (for example user:123:profile). Ask the AI to use atomic commands like INCR for counters and SET ... NX EX for locks rather than read-modify-write sequences that can race. A good tip: have the AI use the cache-aside pattern. That just means: first look in the cache; if it is not there, get it from the database; then save it into the cache for next time. Also ask the AI to explain its invalidation strategy — how old, stale data gets cleared — so out-of-date data does not linger.

# Cache a value with a 1-hour expiry
SET user:123:profile "{\"name\":\"Ada\"}" EX 3600

# Atomic rate-limit counter
INCR rate:ip:203.0.113.5
EXPIRE rate:ip:203.0.113.5 60

# Distributed lock: set only if not exists, auto-expire
SET lock:job:42 "owner-a" NX EX 30

# Leaderboard with a sorted set
ZADD leaderboard 4200 "player:7"
ZREVRANGE leaderboard 0 9 WITHSCORES