Untitled
An in-memory data store, keeps data in RAM for super-fast read/write speeds.
-
Data is key-value based.
-
Single-threaded execution (hence atomicity by default)
- No locking overhead
- No context switching
- No race conditions inside Redis
-
Keep data in memory, but can also persist to disk (optional):
- RDB (Snapshotting)
- Saves periodically.
- Faster startup
- Some data loss possible
- AOF (Append Only File)
- Logs every write operation for durability.
- Slower but safer
// can be hybrid
Supports advanced data structures (not just strings):
| Type |
Description |
Example Use Case |
| String |
Simple key-value |
Cache HTML, tokens, counter, OTP |
| List |
Ordered list of strings |
Message queues, timelines |
| Set |
Unique unordered values |
Tags, likes, deduplication |
| Sorted Set (ZSet) |
Unique values with scores |
Leaderboards, ranking |
| Hash |
Key-value within a key |
User profile, object storage |
// Also support Bitmaps, HyperLogLogs, Streams, Geospatial indexes.
Used for:
- Caching:
- Store database query results to reduce DB load.
- Session management:
- Store user sessions in memory for fast access.
- Leaderboards / counters:
- Use sorted sets to maintain rankings.
- Pub/Sub notifications:
- Real-time chat, notifications, or events.
- No disk I/O, microsecond delivery
- Aware: zero persistence and zero message retention (fire and forget)
- Rate limiting:
- Count requests per IP to prevent abuse.
- Very fast read.
- TTL auto handles expired.
- Shared Redis: shared counter.
- Atomic increment.