All posts

Databases

Redis in 2026: A Field Guide for Developers

Almost everyone meets Redis as a cache and stops there. That undersells it badly. Redis is an in-memory data-structure server — and once you see the data structures as a toolkit, half the hard problems in backend engineering turn into three-line solutions. Here is the field guide.

Jithin Kumar PalepuJune 13, 202613 min read

Redis is the tool you reach for when a database is too slow and a variable is too small. It keeps your data in memory, answers in well under a millisecond, and ships with a dozen purpose-built data structures — counters, sorted sets, streams, even native vector search — that quietly solve the problems backend engineers solve over and over: caching, sessions, rate limiting, leaderboards, job queues, real-time counts, and now retrieval for AI. If you only use it as a cache, you are using maybe a tenth of it.

The name is a clue most people never unpack: Redis stands for REmote DIctionary Server. Salvatore Sanfilippo — “antirez” — wrote it in C in 2009 because his analytics startup needed to track rolling lists of page views faster than MySQL could manage. He open-sourced it, and it became the default in-memory layer for what is now most of the internet. Seventeen years later the core idea is unchanged: a server that exposes rich data structures over the network, held in RAM, manipulated with atomic commands.

Why is Redis so fast?

Three things, mostly. First, the data lives in memory, so there is no disk seek on the hot path. Second, the core commands are O(1) — a GET, a SET, an INCR cost the same whether you hold a thousand keys or a billion. Third, and most misunderstood: the command-execution core is a single-threaded event loop. One thread runs every command, one at a time.

That sounds like a limitation and is actually a feature. A single thread means no locks, no mutex contention, no context-switching between commands — and it is why every Redis command is atomic for free. The common myth is that “single-threaded” makes Redis slow on modern many-core boxes. Not quite: since Redis 6 the network I/O is multi-threaded, and Redis 8 pushed multi-threading further into the query engine — up to roughly 2x throughput on an 8-core machine. The command logic stays single-threaded on purpose. Simplicity is the performance strategy.

The other lever is pipelining: batch many commands into a single network round trip instead of paying the latency tax once per command. The difference is not subtle.

Throughput, single node

SET (no pipeline)~180K ops/sec · p50 0.143 ms
LPUSH (no pipeline)~188K ops/sec · p50 0.135 ms
SET (16-cmd pipeline)~1.54M ops/sec
GET (16-cmd pipeline)~1.81M ops/sec

Pipelining batches commands into one round trip — the same hardware does ~10x more work. Source: redis.io benchmarks.

Redis is fast for a boring reason: it does the simplest possible thing, in RAM, with no locks. The cleverness is in the data structures, not the threading.

The data structures are the real superpower

Memcached gives you strings. Redis gives you a toolkit. The leap in productivity comes from learning to see a problem and reach for the right structure — a sorted set for a leaderboard, a stream for a durable queue, a HyperLogLog for counting millions of uniques in a few kilobytes. Click through the roster below; each one pairs what it is for with the commands you would actually type.

The humble byte blob (up to 512 MB) — and Redis knows when it holds an integer, so counters are atomic and lock-free.

Best for Cache values, atomic counters, feature flags, serialized blobs.

SET user:42 '{"name":"Alice"}' EX 3600   # value + 1h TTL
GET user:42
INCR page:views:/redis-guide              # atomic +1
INCRBY downloads 5

That last tab hides three gems worth calling out. A Bitmap can track whether each of 100 million users was active today in just 12.5 MB — one bit per user. A HyperLogLog estimates the cardinality of a set (unique visitors, say) with ~0.81% error in a fixed 12 KB, no matter how many items you throw at it. And geospatial commands turn a sorted set into a “what’s near me” engine with real Haversine math. None of these need a separate service.

What do developers actually build with it?

Below are the patterns you will reach for most. The point is how little code each one takes — the structure does the work.

Cache-aside (the classic)

Read from Redis; on a miss, query your database, then SET key value EX seconds so the next reader is served from memory. The EX TTL is what keeps the cache honest.

Why it matters The single most common Redis pattern: check the cache, fall back to the database on a miss, write it back with a TTL.

Rate limiting

The cheap version is two commands — INCR a per-user-per-window key, then EXPIRE it. For a true sliding window, add request timestamps to a sorted set and trim the ones that fall outside the window with ZREMRANGEBYSCORE.

Why it matters A counter plus an expiry is a fixed-window limiter; a sorted set gives you a precise sliding window.

Leaderboards

ZADD to set scores, ZREVRANGE 0 9 for the top ten, ZREVRANK for any player’s position. A real-time game leaderboard is genuinely three commands.

Why it matters The sorted set is purpose-built for ranking: scores stay ordered, rank lookups are logarithmic, and top-N is one command.

Job queues

LPUSH + blocking BRPOP is the minimal worker queue. When you need durability — redelivery on crash, multiple competing consumers — graduate to Streams with XADD / XREADGROUP / XACK.

Why it matters A list gives you a fire-and-forget queue; a stream with consumer groups gives you at-least-once delivery and acknowledgements.

Distributed locks

SET lock:resource <token> NX PX 30000 sets the lock only if it does not exist and auto-expires it in 30 seconds, so a dead holder can never deadlock you. Release by checking the token and deleting — in a Lua script so the check-and-delete is atomic.

Why it matters A single atomic command gives you a mutex across processes — the foundation of the Redlock algorithm.

# Sliding-window rate limit (≤ 100 requests / 60 s per user)
ZADD   rate:user:42 <now_ms> <request_id>
ZREMRANGEBYSCORE rate:user:42 0 <now_ms - 60000>
ZCARD  rate:user:42          # > 100 ? reject : allow
EXPIRE rate:user:42 60

Redis for AI: vectors, RAG, and semantic caching

This is the part that makes Redis newly relevant to anyone building with LLMs. As of Redis 8 the old “Redis Stack” modules — search, JSON, time series — are bundled into the core, and antirez shipped a native Vector Set type for similarity search. That turns Redis into a credible vector database with sub-millisecond retrieval.

  • RAG retrieval. Store your text chunks and their embeddings, index them with the Redis Query Engine (FT.CREATE), and pull nearest neighbours with a KNN FT.SEARCH. Redis 8.4 added FT.HYBRID, which fuses full-text and vector scores into one ranked result — no merging in your application code.
  • Semantic caching. Cache LLM completions keyed by embedding similarity: if a new prompt is within a cosine threshold of one you have already answered, serve the cached completion. It cuts both latency and API spend.
  • Agent memory. The same speed that makes Redis a good cache makes it a natural short-term and session memory store for agents — exactly the kind of layer we explored in our piece on memory systems for AI agents.

It is worth being honest about scope: Redis is not always the right retrieval layer. We argued in why your AI agents need a terminal, not just a vector database that vector search is one tool among several. But when you want fast, in-process similarity search next to data you are already caching, having it in Redis removes a whole moving part from your stack.

How does Redis keep your data safe and scale?

“In-memory” worries people, but Redis is not amnesiac. It offers two persistence modes, usually run together:

  • RDB snapshots — periodic point-in-time dumps of the whole dataset via a copy-on-write fork. Compact and fast to restart from, but you can lose the minutes between snapshots.
  • AOF (append-only file) — logs every write. With fsync everysec (the default) you risk at most one second of data; with always, effectively none.
  • Hybrid — modern Redis writes an RDB preamble inside the AOF, so restarts load a compact snapshot and then replay only the recent tail. Use this in production.

For scale and availability there are three layers. Replication gives you read replicas and hot standbys. Sentinel adds automatic failover — it watches the primary and promotes a replica if it goes dark. Cluster shards your keyspace across nodes using exactly 16,384 hash slots (a key’s slot is CRC16(key) % 16384), letting you scale writes horizontally past a single machine’s memory.

The gotchas that bite in production

Redis is forgiving until it isn’t. Most outages trace back to a handful of mistakes:

  1. Never run KEYS * in production. It is O(N) and blocks the single event loop for the entire scan — on a large instance, that is a multi-second freeze for every client. Use SCAN with a cursor instead. The same caution applies to SMEMBERS and LRANGE 0 -1 on huge collections.
  2. Watch for big keys. A multi-megabyte value or a collection with hundreds of thousands of elements saturates the network and blocks the loop on deletion. Delete them with UNLINK (background) rather than DEL, and hunt them with redis-cli --bigkeys.
  3. Set an eviction policy. The default is noeviction — once maxmemory is hit, writes start returning errors. For a cache you almost always want allkeys-lru or allkeys-lfu.
  4. Jitter your TTLs. If a popular key expires and hundreds of requests miss the cache at once, they stampede your database. Add randomness to expiry times and consider a per-key lock so only one request refills the cache.

What happened with the Redis license? (Valkey, explained)

If you stepped away from Redis in 2024, the licensing picture has whiplashed — and it matters for what you deploy. In March 2024, Redis Ltd. relicensed from the permissive BSD to a dual SSPL/RSAL model, neither OSI-approved, aimed at stopping cloud providers from selling managed Redis without giving back. The community revolted, and within days the Linux Foundation launched Valkey — a BSD-licensed fork of Redis 7.2 backed by AWS, Google Cloud, and Oracle. AWS ElastiCache and Google Memorystore quietly switched their defaults to Valkey.

Then the plot turned. Antirez rejoined Redis in late 2024, and with Redis 8.0 (May 2025) the company added AGPLv3 — a real, OSI-approved open-source license — as a third option alongside SSPL and RSAL. So today Redis 8.x is tri-licensed: pick AGPLv3 and you are back on genuine open source. The fork still thrives, which leaves developers with a real choice.

 Redis 8.xValkeyDragonflyDB
LicenseAGPLv3 / SSPL / RSALBSD-3-ClauseBSL 1.1
GovernanceRedis Ltd.Linux FoundationDragonfly Inc.
AI / modulesFull (vector, search, JSON built-in)GrowingLimited
Pick it whenYou want Vector Sets & hybrid searchYou want a neutral BSD drop-inYou want max single-node throughput
The 2026 in-memory landscape. Valkey is the open-governance fork; DragonflyDB is the performance-first challenger. All three speak the Redis protocol.

Versus Memcached, the call is easy: Memcached is a pure string cache — no data structures, no persistence, no scripting. Reach for it only if all you will ever do is cache strings. For everything else, Redis (or a Redis-compatible engine) wins on capability.

So, should you use Redis?

For caching, sessions, rate limiting, queues, leaderboards, real-time counters, and increasingly vector retrieval — yes, almost reflexively. The reason isn’t raw speed, which its competitors now match or beat; it is the breadth of the toolkit. Learning the data structures is a permanent upgrade to how you design backends, because you start seeing problems in terms of the structure that dissolves them.

The honest caveats: it is memory-bound, so a careless schema gets expensive; the single-threaded core punishes O(N) commands on big keys; and you should pick your license (AGPL) and your engine (Redis vs Valkey) deliberately rather than by habit. None of that is a reason to avoid it — just reasons to use it well.

Sources and further reading: the Redis 8 GA announcement, Redis on adding AGPLv3, the Linux Foundation’s Valkey launch, and the official Redis benchmarks.

Everything that matters in AI,
straight to your inbox.

Join 12,000+ readers — daily, free, no spam.