キャッシング はRedisの最も一般的なユースケースであり、頻繁にアクセスされるデータを高速なメモリに保存することで、アプリケーションがより遅い操作(データベースクエリ、API呼び出し、計算)を回避できるようにします。基本的なキャッシングパターンを理解することは、欠かせない日常的な知識です。
cache-asideパターン(最も一般的)
1. App needs data → CHECK Redis first (cache lookup)
2. CACHE HIT (found) → return it immediately (fast!) ✓
3. CACHE MISS (not found) → query the database, store the result in Redis (with TTL),
then return it. Next time it'll be a hit.
() {
cached = redis.();
(cached) .(cached);
user = db..(id);
redis.(, .(user), , );
user;
}
