What Is Redis? β Definition and How It Works
Learn what Redis is, which data structures it provides, how persistence and expiry work, and the roles it plays in collection pipelines.
Redis is an in-memory data store. It holds data in RAM, which makes operations extremely fast, and it provides data structures rather than only key-value pairs.
1. The Data Structures
| Structure | Useful for |
|---|---|
| String | Caching, counters, flags |
| Hash | An object with fields |
| List | Queues, recent-item buffers |
| Set | Membership β seen URLs, deduplication |
| Sorted set | Priority queues, rate limiting, leaderboards |
| Stream | Append-only event logs with consumer groups |
| Bitmap and HyperLogLog | Compact presence and approximate counts |
Having these server-side means operations are atomic and the round trip returns an answer rather than data to process locally.
2. Expiry Is First-Class
Any key can carry a time to live, after which it is removed automatically.
That single feature underpins most of its use: cache entries that self-clean, rate-limit counters that reset, session tokens that expire, and locks that release even if a worker dies.
3. Roles in a Collection Pipeline
- Deduplication β a set of seen identifiers, checked before fetching.
- Rate limiting β counters or sorted sets shared across workers, so a fleet stays within one budget.
- Distributed locks β preventing overlapping runs of the same job.
- Queues β lists or streams distributing URLs to workers.
- Caching β responses that need not be refetched within a window.
- Coordination β shared state that would otherwise require a database round trip.
The rate-limiting role is the one most often missing: without shared counters, each worker is individually compliant and the fleet collectively is not.
4. Persistence
Despite being in-memory, it can persist: periodic snapshots, an append-only log of writes, or both.
The trade is between durability and performance, and the honest framing is that Redis is a fast store with persistence options rather than a durable database with a cache in front.
5. Memory Is the Constraint
Everything lives in RAM, so the dataset must fit. When memory fills, an eviction policy decides what goes β least recently used, least frequently used, or nothing, in which case writes fail.
Choosing that policy deliberately matters: a cache should evict, while a queue should not silently discard work.
6. Atomicity
Individual commands are atomic, and multi-step operations can be made atomic with transactions or a server-side script.
This is what makes correct distributed counters and locks possible β a check-then-set implemented as two round trips is a race, and the same logic executed server-side is not.
7. Practical Notes
- Set expiry on everything that is not permanent state.
- Use a sorted set for sliding-window rate limits, storing timestamps as scores.
- Give locks a timeout so a crashed worker cannot hold one forever.
- Watch memory, and alert before eviction begins.
- Avoid very large single values, which block the server while they are handled.
8. Summary
Redis is an in-memory store providing atomic data structures with optional persistence and first-class expiry.
In a collection pipeline it does the coordination work: deduplication sets, shared rate-limit counters, distributed locks, queues, and caches β all of which depend on speed and atomicity rather than durability.