A S T A C O D E

Loading

Tutorial

Redis untuk Developer: Caching, Session, dan Pub/Sub

Admin

Author

Jul 28, 2026

Published

29

Views

Redis untuk Developer: Caching, Session, dan Pub/Sub

Setup Redis

Docker: docker run -d -p 6379:6379 redis:7-alpine. Untuk production, gunakan Redis Cloud, Upstash, atau ElastiCache. Install client: npm install ioredis.

Caching Pattern

Cache-aside pattern: check cache first, jika miss ambil dari DB dan populate cache. Selalu set TTL yang reasonable. Cache invalidation strategy: time-based atau event-based.

Session Storage

Gunakan express-session dengan connect-redis store untuk session yang scalable. Berbeda dari JWT, session server-side memungkinkan instant revocation.

Rate Limiting

Sliding window rate limiter dengan Redis: gunakan sorted sets untuk track request timestamp per user. Library redis-rate-limiter menyederhanakan implementasi ini.

Pub/Sub Messaging

Redis Pub/Sub cocok untuk simple message broadcasting antar service: redis.publish('channel', message) dan redis.subscribe('channel', handler).

Data Structures yang Harus Diketahui

  • String: simple cache, counter
  • Hash: object storage, user session
  • List: queue, timeline
  • Set: unique tags, membership
  • Sorted Set: leaderboard, rate limiter

Looking for a professional partner?

Let's discuss how we can help your business grow with our technology solutions.

Chat with us