~/VibeHandbook
$39

Databases

redis.io

Redis

What it is

Redis is an in-memory data store that keeps data in RAM for extremely fast reads and writes, with optional persistence to disk. 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 cache, session store, queue, or rate limiter alongside a primary database.

Strengths

  • Sub-millisecond latency thanks to in-memory operation.
  • Versatile structures: strings, hashes, lists, sets, sorted sets, streams.
  • Built-in TTL/expiry 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 and 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 implement a cache-aside pattern (read cache, fall back to the database, then populate the cache) and explain the invalidation strategy so stale 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