Index/Redis

SponsorGitHub
Key technologyIn-memory store4 min

Redis

Sub-millisecond memory with useful data structures: caches, counters, locks, leaderboards and rate limits.

At a glance

Model
Keys holding real data structures, not just blobs
Threading
One command at a time per shard, so operations are atomic without locks
Latency
Tens of microseconds; the network round trip dominates
Durability
Optional RDB snapshots or AOF; a crash can lose the last second
Availability
Async replicas, Sentinel promotes on failure
Sharding
Redis Cluster, 16,384 slots; hash tags keep related keys together

Key concepts and capabilities

The short listwhat it gives you
Data structures are the point — strings and INCR, hashes, lists, sets, sorted sets, streams, bitmaps and HyperLogLog
Single-threaded per shard — one command at a time, so every operation is atomic with no lock of your own
Lua for multi-step work — check a bucket, decrement it, re-arm the TTL, all as one unit on the server
TTL and eviction — every key can expire; allkeys-lru for a pure cache, volatile-ttl when some keys must stay
Nothing may depend on a key existing — it can be evicted at any moment
Pub/sub is fire-and-forget; Streams keep history and support consumer groups with acks
Pipelining — 100 commands in one round trip, because the round trip is the cost
Durability is optional — RDB snapshots or AOF fsynced ~1s, so treat it as authoritative only for rebuildable data
Cluster hash tagsuser:{123}:feed keeps related keys in one slot so multi-key commands work

Use cases

Cache-aside in front of a database

The most common use by far, and the interesting part is never the cache itself: it is the TTL, who deletes the key on write, and what a thousand simultaneous misses do to the database behind it.

DatabaseCacheFocusClick a node for details

Rate limiting that is actually global

Counters in each application instance let through N times your limit. One Redis holds the bucket for every instance, and a Lua script makes refill-and-spend a single atomic step. The TTL is the window, so idle keys evict themselves and there is no cleanup job.

A sorted set keeps members ordered by score for free, so the top ten is a range read rather than a scan and a sort. The same structure holds a time window: score by timestamp, trim the old end, and the set is always "the last five minutes".

CacheFocusClick a node for details

A doorbell for a socket tier

Pub/sub is how a message reaches the one server holding a user's connection without a registry lookup. It is a doorbell, not a delivery guarantee: the message is already durable before the publish, and a missed publish is repaired by the client's reconnect.

DatabaseCacheFocusClick a node for details