1.What Redis is actually used for beyond caching
Redis is best known as a cache, but its speed and atomic operations make it a fit for anything that needs fast, shared, short-lived state — counters, session storage, rate limiting, lightweight coordination locks, and simple queues. The common thread across all of these is: state that many instances need to share, updated frequently, where losing it is tolerable or backed up elsewhere.
Key features
- Caching: the most common use — storing expensive-to-compute results with a TTL
- Counters: Redis's atomic INCR/DECR make it a natural fit for view counts, rate-limit counters, or leaderboard scores
- Session storage: session data shared across multiple stateless application instances, instead of living in one instance's memory
- Rate limiting: atomic increment-and-check patterns implement token bucket or sliding window limits without a race condition
- Lightweight coordination: simple distributed locks (SET key value NX EX ttl) for short-lived mutual exclusion — not a substitute for a real consensus system for anything critical
- Queues: Redis lists or streams as a simple message queue when a full broker like Kafka or RabbitMQ would be overkill
Redis use cases and the primitive behind each
- Cache — string/hash + TTL
- Counter — atomic INCR/DECR
- Session store — shared across instances
- Rate limiter — INCR + EXPIRE
- Lightweight lock — SET NX EX
- Simple queue — list or stream
Command
INCR page_views:42 -- atomic counter
SET session:abc "{...}" EX 1800 -- session with TTL
SET lock:job-1 "worker-a" NX EX 30 -- lightweight lock
LPUSH queue:emails "{...}" -- simple queue pushRedis fits anything that needs fast, shared, short-lived state: caching, atomic counters, session storage, rate limiting, lightweight locks, simple queues — not as a substitute for a durable primary store or a full-featured message broker when the workload genuinely needs one.