Redis
Redis (REmote DIctionary Server) is the most-deployed NoSQL system in the world. Created by Salvatore Sanfilippo in 2009, it is an in-memory data-structure server that exposes strings, hashes, lists, sets, sorted sets, streams, hyperloglogs, bitmaps, and geospatial indexes over a simple text protocol (RESP). Redis is single-threaded for command execution, making operations atomic by default, and routinely sustains hundreds of thousands of operations per second per node from one or two CPU cores.
Key Features:
- Rich Data Types. Beyond strings:
HSET, LPUSH, SADD, ZADD (sorted sets / leaderboards), XADD (streams), PFADD (HyperLogLog), GEOADD. Each command is an atomic operation against a server-side data structure.
- Sub-Millisecond Latency. p50 read / write latency around 100µs on local network, p99 typically under 1ms with reasonable load.
- Persistence Options. RDB (point-in-time snapshots), AOF (append-only log), or both. Tunable durability vs. throughput.
- Replication & Sentinel. Async master-replica replication; Redis Sentinel for automatic failover monitoring.
- Redis Cluster. Native sharding across 16,384 hash slots with automatic resharding and failover.
- Pub/Sub & Streams. Lightweight messaging via channels; durable Kafka-style log via
XADD / XREADGROUP.
- Lua Scripting & Functions. Atomic multi-step transactions via
EVAL or Redis Functions.
- Modules. RediSearch, RedisJSON, RedisTimeSeries, RedisBloom, RedisAI, Redis-Vector — turn Redis into a search engine, JSON store, time-series DB, or vector index.
Common Use Cases:
- Cache. The default cache layer in front of slower databases.
- Session Store. Web/API session state with TTL.
- Rate Limiting. Token-bucket / sliding-window via
INCR + EXPIRE or sorted sets.
- Leaderboards.
ZADD + ZREVRANGE for ranked, gamified scoring.
- Queue / Task Broker. Sidekiq, Bull, Celery, RQ, Resque all use Redis lists or streams.
- Pub/Sub Fan-Out. Real-time chat, notifications, dashboards.
- Distributed Locks. RedLock pattern for cross-process mutual exclusion.
- Feature Store / Embeddings. RedisJSON + RedisSearch + Redis-Vector for low-latency RAG retrieval.
Redis vs. Memcached:
- Redis. Rich data types, persistence, replication, cluster, pub/sub, scripting. The default choice for almost every new system.
- Memcached. Strings only, multi-threaded, no persistence, no replication. Simpler and faster for the narrow case of pure ephemeral cache where Redis’ features are unused.
Operational Notes:
Single-threaded command execution caps a single Redis instance at one CPU core for data work; scale by clustering or running multiple instances. Memory is the bottleneck — eviction policies (allkeys-lru, volatile-lru, allkeys-lfu) determine behavior when maxmemory is reached. Always set maxmemory in production; OOM-kill of Redis is a recurring outage source.