Redis in plain words: cache, queue, and lock
Redis is an in-memory data structure server you use as a cache, list queue, or short lock, not a mystery database.
Published here , updated · 6 sources · Resume reading
Redis is an in-memory data structure server: strings, hashes, lists, sets, sorted sets, streams, and more, with optional persistence [1] [2]. Most app teams meet it first as a cache. The same process can also hold a job list or a short-lived lock [2] [5]. Related stack restraint: cloud complexity you do not need.
Quick start (under a minute)
After you install Redis and start redis-server per the quick start [3], connect with:
redis-cli pingYou should see PONG. That proves the TCP listener on the default port answered [3].
Redis was not running on this draft host, so the line below is the expected shape per the docs, not a measurement here [3] [4].
PONGDraw three jobs on one server
Redis keeps values in memory for speed [1]. Persistence is optional: RDB snapshots, append-only file, or off for a pure networked cache [1]. Before you add a second pattern on the same cluster, write down which keys are cache (safe to lose) versus queue (must survive until acknowledged). That one sentence saves you from sharing one eviction policy between unrelated teams.
Name three jobs, not one buzzword
| Job | Redis shape (from docs) |
|---|---|
| Cache | String key with TTL via SET expiration options [4] |
| Queue | List push/pop, or streams for append-only logs [2] |
| Lock | SET with NX plus TTL, then full lock pattern [4] [5] |
The About page: Redis can run as an in-memory dataset with optional dumps or AOF, or without persistence when you only need a shared remote cache [1].
Try a TTL cache in redis-cli
redis-cli -h 127.0.0.1 -p 6379Example session shape per the SET and TTL command docs [4]:
127.0.0.1:6379> SET session:demo "ok" EX 60
OK
127.0.0.1:6379> GET session:demo
"ok"
127.0.0.1:6379> TTL session:demo
(integer) 58You should see OK, the string value, then a TTL counting down toward zero. After expiry, GET returns (nil) [4]. Replace session:demo with namespaced keys your app owns.
Hashes suit objects with fields (HSET user:1 name "Ada"). Lists suit FIFO work queues (LPUSH / BRPOP). Streams suit ordered events consumers read in groups [2].
Keep queues and locks honest
Lists preserve insertion order for push/pop style workers [2]. Streams add consumer groups and replay semantics for event pipelines [2].
For locks, the distributed locks guide documents acquiring with SET using NX and an expiration, then additional rules so only the holder releases the key [5]. A single command is not a production lock. Measure latency and failure modes before you bet invoice correctness on Redis TTL locks.
Run a list queue sketch
For a FIFO worker, Redis lists support push and blocking pop [2]. Example session shape per list command docs:
127.0.0.1:6379> LPUSH jobs:ingest "task-1"
(integer) 1
127.0.0.1:6379> LPUSH jobs:ingest "task-2"
(integer) 2
127.0.0.1:6379> BRPOP jobs:ingest 5
1) "jobs:ingest"
2) "task-1"Workers should handle poison messages: if processing fails, use a dead-letter list rather than infinite retry loops. Streams add consumer groups when you need acknowledgment semantics beyond a simple list [2].
Name keys like you mean maintenance
Use colon namespaces (app:cache:user:42) so pattern deletes and ACL rules stay scoped [3]. Random bare keys become archaeological sites. Document TTL policy per prefix: session keys expire in hours, config caches in minutes, feature flags perhaps without TTL when size is bounded.
Persistence and memory limits
When Redis restarts without RDB or AOF, in-memory keys are gone [1]. Plan caches to refill. Plan queues with idempotent workers if messages can disappear mid-crash.
Memory is finite. Eviction policies (maxmemory-policy) decide what happens when the dataset fills. Caches can drop old keys; queues should not silently evaporate work you still need. Read redis.conf comments before you turn knobs in production.
Clients and connection pools
Application clients open TCP connections to Redis and issue commands defined in the protocol [3]. Connection pools reuse sockets so you do not pay setup per request. TLS and ACL usernames add configuration but do not change the teaching model: commands in, typed replies out.
Watch CLIENT LIST when debugging ghost connections after deploys. Stale clients holding keys without TTL still consume memory until they disconnect.
Authentication and ACLs (outline)
Modern Redis supports ACL users with command allow lists [1]. Production clusters disable FLUSHALL for application users and separate admin credentials. This page does not reproduce every ACL rule; read redis.conf and your vendor wrapper when you leave localhost.
Sorted sets power leaderboards with score-ordered members [2]. HyperLogLog sketches approximate cardinality with tiny memory. You do not need those types on day one, but they show why Redis is a structure server rather than a single GET/PUT cache.
Benchmark before you mirror relational tables row for row. Foreign keys, joins, and ad hoc reporting remain relational jobs unless you deliberately model otherwise.
Pub/sub channels notify subscribers without storing history [2]. Use streams or lists when a consumer must read after reconnecting. The wrong primitive looks fine in a demo and loses messages in production.
Replication and Sentinel or cluster modes add failover stories beyond a single redis-server on localhost [1]. Start simple, measure latency to a managed instance, then read the ops guide before you promise five-nines on one VM.
Health checks in orchestrators often call redis-cli ping or issue a harmless PING command from your app client [3]. Treat timeouts as deployment signals, not as an excuse to disable persistence without a written decision.
Document which keys are safe to delete during incidents. A panicked FLUSHDB fixes one outage and creates another.
When you outgrow one instance, read the clustering guide before you shard by gut feel [1]. Hot keys on a single hash slot negate the point of horizontal scale. Instrument memory and eviction counters before you blame application code for latency spikes.
Common mistakes and misconceptions
Adding Redis because "every stack has Redis" without naming the job (cache, queue, or lock).
Using Redis as the system of record for money without durability settings you understand.
Forgetting key TTLs and wondering why memory climbed forever.
Treating SET NX as a complete distributed lock across crashes and clock skew [5].
Running one shared Redis for unrelated teams without key prefixes and ACLs.
Single-threaded Redis means zero contention. Hot keys still serialize.
Write the TTL prefix policy in your repo README before you paste SET into production code. A cache without expiry is a memory leak with extra steps. Your next experiment: pick one hot read endpoint, add a five minute TTL key, graph hit rate and eviction counters for a day, then decide whether a queue or lock belongs on the same instance.
Send this to the friend who adds Redis before measuring one slow query.

Keep this guide
Filed under Dev explainers, Dev tools
Questions about this guide
Is Redis only a cache?
No. Redis describes itself as an in-memory database and data structure server. TTL strings are one pattern; lists, streams, and sets are others.
Does data survive a restart?
Only if you enable persistence. Redis docs document RDB snapshots, AOF logs, or disabling persistence for a pure cache.
How do I set a cache entry that expires?
SET with an expiration option such as EX seconds, then confirm with GET and TTL.
Is SET NX a complete distributed lock?
SET with NX and a TTL is one step in Redis lock docs. Production locks need the full pattern including safe release.
When should I not use Redis?
When you need complex relational queries, strong durability by default, or large cold datasets that do not fit memory.
Sources
- Full Byte Developer: Cloud complexity you do not needfullbytedeveloper.com