Glossary
108 terms from Redis and Caching, in plain words, each with the chapter that teaches it.
A
- ACL (access control list)
- A Redis feature that gives each user only the commands and key patterns it needs. The API user can be limited to `kc:*` keys and barred from dangerous commands like `FLUSHALL`.
- allkeys-lfu
- An eviction policy that, when memory is full, deletes the key used least often across all keys. It keeps popular keys.
- allkeys-lru
- An eviction policy that deletes the least recently used key when memory is full. It is the right choice for a Redis that holds only cache data, because every key can be rebuilt.
- AOF (append-only file)
- A persistence method that logs every write to a file as it happens and replays it on restart. With `appendfsync everysec`, a crash loses at most about a second of writes.
- Atomic
- Describes an operation that runs completely before any other command can start. Because `INCR` is atomic, three API servers incrementing a counter of 10 get 11, 12 and 13 instead of losing visits.
- AUTH
- The command that sends a password, or a username and password, to a Redis server. Without it, a password-protected server answers `NOAUTH Authentication required`.
B
- Background job
- Work the API hands off to be done later, outside the request. Sending a receipt email after `POST /orders` is an example.
- Basic Redis commands (SET, GET, DEL, EXISTS, PING, MSET, MGET)
- `SET` saves a value under a key and `GET` reads it back (`(nil)` if missing). `DEL` deletes keys, `EXISTS` counts which keys exist, `PING` answers `PONG` to show the server is there, and `MSET`/`MGET` set or read several keys at once.
- BGSAVE
- A command that makes Redis take an RDB snapshot to disk now, in the background.
- Big key
- A value so large, such as a list of a million items, that reading or deleting it is slow and makes other clients wait. Splitting it into smaller keys fixes this.
- BRPOP
- A blocking pop: it removes the rightmost item of a list, or waits up to a timeout for one to arrive. Workers use it to take jobs from a queue. `LMOVE` and `BLMOVE` instead move the job to a processing list so a crash doesn't lose it.
- BullMQ
- A Node.js library that builds job queues on top of Redis, adding retries, delays and monitoring. It is a common next step after simple Redis list queues, which lack those features.
C
- Cache
- A fast place to keep a copy of an answer so you don't have to work it out again. Kettle & Crane keeps a copy of the menu in Redis so pages don't query the database every time.
- Cache hit
- A lookup where the cached copy is found, so the slow work is skipped.
- Cache miss
- A lookup where no cached copy exists. You do the slow work and save the result for next time.
- Cache stampede
- A rush of requests that all miss at once and all rebuild the same value, which can overload the database. It happens when a popular key like `kc:menu` expires on a busy morning.
- Cache-aside
- A pattern where the route code checks the cache first. On a miss it loads from the database, saves a copy in Redis and returns it.
- Cache-Control
- An HTTP header telling browsers and CDNs what they may keep and for how long. `public, max-age=60` lets anyone keep a response for 60 seconds, `private` allows only the user's browser, and `no-store` allows no one.
- CDN (content delivery network)
- Servers around the world that keep copies of responses near users. A CDN is another cache, controlled by headers like `Cache-Control`.
- Channel
- A named place, such as `kc:menu-changed`, where pub/sub messages are published and received.
- Client, server
- The client is the program that sends commands, such as the Kettle & Crane API. The server is the program that answers them, such as Redis.
- CONFIG SET
- Commands that read or change a setting on a running Redis server, such as `maxmemory-policy`. `CONFIG RESETSTAT` sets the statistics counters back to 0.
- Consumer group
- A set of readers that share a stream, with each entry going to only one of them. `XREADGROUP` reads entries and `XACK` confirms them as done.
- Cookie
- A small named value the browser stores for a site and sends back with each request. Priya's session id travels in a cookie called `sid`.
- Cursor
- The position that `SCAN` returns so you can continue with the next batch. It starts at `0`, and a returned `0` means the scan is finished.
D
- Database (Redis)
- One of the numbered keyspaces, 0 to 15, inside a Redis server, each with its own keys. `SELECT 1` or a URL ending `/1` picks one; the tests use database 15.
- Delete-on-write
- Invalidating by deleting cached copies after the database update succeeds, so the next read reloads fresh data. It avoids the race where a slow reader writes an old menu back.
- Denylist
- A list of tokens that are no longer allowed, each kept in Redis until the token would have expired anyway. It lets JWTs be revoked.
- disableOfflineQueue
- A node-redis option that makes commands fail at once when Redis is down, instead of queuing and hanging. It is paired with `socket.connectTimeout` and `socket.reconnectStrategy` to fail fast.
- duplicate()
- A node-redis method that makes a second connection with the same settings. Pub/sub subscribers and blocking workers need their own connection because a busy connection can't run other commands.
E
- ETag
- A header that tags the version of a response. The browser sends it back in `If-None-Match`, and if nothing changed the server answers `304 Not Modified` with no body.
- Eviction policy
- The rule Redis follows to delete keys and make room when `maxmemory` is reached. Examples are `allkeys-lru` and `noeviction`.
- Expiry commands (EXPIRE, PERSIST, KEEPTTL)
- `EXPIRE` gives an existing key a lifetime in seconds (`PEXPIRE` in milliseconds), and `EX`/`PX` on `SET` do the same while saving. `PERSIST` removes a TTL so the key stays forever, and `SET ... KEEPTTL` overwrites a value without clearing its TTL, which a plain `SET` would.
F
- Fail open, fail closed
- What to do when a helper like Redis can't be used. Failing open carries on without it, as a cache does by going to the database. Failing closed refuses the request instead.
- Failover
- When the primary Redis dies and its replica is promoted to take over, automatically on managed services. Writes the primary accepted just before dying may be missing.
- Fire-and-forget
- A delivery style where a message is sent once to whoever is listening and kept nowhere. Pub/sub works this way, so an offline subscriber misses the message.
- Fixed window
- A rate limit that counts requests per block of time, such as each 15 minutes. It is simple but weak at the edges of windows.
- FLUSHALL
- A command that deletes every key in every database. `FLUSHDB` clears only the current database. Block them with ACLs on production.
- for await
- A `for...of` loop that waits for each value to arrive, used with `scanIterator` to handle each batch of keys.
H
- Hash
- A Redis value holding named fields, like a small object. Kettle & Crane's product and session data can be stored this way.
- Hit ratio
- Hits divided by all lookups. With 90 hits and 10 misses it is 0.9, or 90%.
- HTTP status codes
- Three-digit numbers a server sends to say how a request went. Common ones are 200 (OK), 304 Not Modified (your copy is still current, no body), 400 (bad input), 401 (not logged in or wrong password), 404 (not found) and 429 Too Many Requests (over the rate limit).
- HttpOnly, Secure, SameSite
- Cookie settings that keep a session cookie safe. `HttpOnly` hides it from page scripts, `Secure` sends it only over HTTPS, and `SameSite=Lax` keeps it off most requests that start on other sites.
I
- In memory
- Kept in the computer's RAM rather than on disk, which makes reads very fast but means data is lost on restart unless persistence is on.
- INCR
- An atomic command that adds 1 to a number stored in a key and returns the new value. A missing key counts as 0. `INCRBY` adds any amount and `DECR` subtracts 1.
- INFO
- A command that prints a server's statistics. `INFO memory` shows memory use, and `INFO stats` shows evictions plus `keyspace_hits` and `keyspace_misses`.
- Invalidation
- Removing or replacing cached data that may have gone stale, such as clearing `kc:menu` when Jo changes a price.
J
- Jitter
- A small random amount added to each TTL so keys created together don't all expire together.
- jti
- A JWT claim holding a unique token id. Storing it in a denylist lets a server revoke that one token. `exp` is the claim holding the expiry time.
- JWT (JSON Web Token)
- A signed login token the server checks by its signature alone, so it can't be taken back before its `exp` time unless you add a denylist.
K
- Key-value store
- A store where each value is saved under a name, its key, and read back by that key. Redis is one.
- KEYS
- A command that lists keys matching a pattern, with `*` meaning anything. It checks every key and can freeze a busy server, so production code uses `SCAN`.
L
- Latency
- The time you wait for an answer. A Redis read takes about a millisecond, while a database query can take 150 ms.
- LFU (least frequently used)
- An eviction approach that removes the keys used least often.
- List
- A Redis value holding strings in order. Kettle & Crane uses one for recent orders and as a simple job queue.
- Lock
- A key that lets only one caller do a job at a time. `SET key 1 NX PX 5000` sets it only if absent and expires in 5 seconds, so one request rebuilds the menu while others wait.
- LRU (least recently used)
- An eviction approach that removes the key that hasn't been used for the longest time.
- Lua script
- A small script Redis can run as one atomic command, which is another way to build rate limiters.
M
- Managed Redis
- Redis run for you by a cloud service that handles hosting and backups and gives you a TLS URL.
- maxmemory
- A setting that caps how much memory Redis may use. When it's reached, the eviction policy decides what happens.
- MULTI
- `MULTI` starts a transaction, later commands are queued, and `EXEC` runs them together. The rate limiter uses it so `INCR` and `EXPIRE` run as a unit.
N
- node-redis
- The official Node.js client for Redis, installed with `npm install redis`. It has a camelCase method for each command.
- noeviction
- An eviction policy where Redis refuses writes with an OOM error when memory is full. Nothing is lost, so it is the safe choice for sessions.
O
- OOM (out of memory)
- The error `OOM command not allowed when used memory > 'maxmemory'` that a full Redis gives under `noeviction`.
P
- Pending entries
- Stream entries a consumer group has received but not yet acknowledged with `XACK`. They let another worker take over after a crash.
- Persistence
- Writing Redis's in-memory data to disk so it survives a restart. Redis does this with RDB snapshots, an AOF log, or both.
- preHandler
- A Fastify hook that runs before the route handler and can stop it by throwing. The `rateLimit()` function returns one.
- Producer
- The code that adds jobs to a queue, such as the order route. The worker takes jobs off and does them.
- Promise.race
- A JavaScript function that settles as soon as the first promise in its list does. `connectRedis` races the connection against a 2-second timer so the API starts even with Redis down.
- Protected mode
- A Redis default that refuses connections from other machines when no password is set. `bind 127.0.0.1` makes Redis listen only on its own machine.
- Pub/sub (publish/subscribe)
- A way to send a message to every program currently listening on a channel. Redis stores nothing, so a subscriber that's offline never sees the message.
Q
- Queue
- A line of background jobs waiting to be done. A Redis list can serve as a simple queue.
R
- Race condition
- A bug that depends on the timing of two things. Examples are a slow reader overwriting a fresh menu, or a crash between `INCR` and `EXPIRE`.
- Rate limit
- A cap on how many requests one client may make in a period, such as 5 login attempts per 15 minutes per IP. Over the cap, the API answers 429.
- RDB (Redis Database file)
- A persistence method that saves a snapshot of all data to `dump.rdb` at set intervals. A crash loses changes since the last snapshot.
- Read-through
- A pattern where the cache layer itself loads missing data from the database, as the `cached()` helper does for callers.
- Redis
- A separate server program that keeps data in memory as a key-value store and answers commands over the network, by default on port 6379.
- Redis Insight
- A free app that shows your Redis data in a window, grouping keys by their colons.
- Redis URL
- An address naming the Redis host, port and optionally user, password and database, such as `redis://api:pass@host:6379/0`. A `rediss://` URL turns on TLS; keep it in the `REDIS_URL` environment variable, not in code.
- redis-cli
- Redis's command-line client. You type commands such as `SET` and `GET` at its prompt, or pass one command from the shell.
- Replica
- A second Redis that copies every write from the primary, the server that takes writes. It can take over if the primary fails.
- Retry-After
- A response header giving the seconds to wait before trying again, sent with a 429. `X-RateLimit-Limit` and `X-RateLimit-Remaining` show the requests allowed and the requests left.
- Revocation
- Ending a login before it would expire. With Redis sessions it is one `DEL`, while JWTs need a denylist.
S
- SCAN
- A command that lists keys in small batches using a cursor, so it doesn't freeze a busy server the way `KEYS` can. `MATCH` filters by pattern and `COUNT` suggests a batch size.
- Serialization
- Turning an object into text, such as JSON, to store it in Redis, and turning it back when reading.
- Session
- The server's record of one logged-in visit, such as Priya's, stored in a Redis hash. The long random session id travels in a cookie and finds it.
- Set
- A Redis value holding unique strings in no particular order. Adding a repeat is ignored.
- Single point of failure
- One machine whose failure stops the whole system. A single Redis is one, which is why replicas and a cache that fails open matter.
- Sliding expiration
- Pushing a TTL back on every use, so a session ends after 30 minutes of inactivity rather than 30 minutes after login.
- Sliding window log
- A rate limit that keeps each request's time in a sorted set and counts only those within the last window. It is exact but stores an entry per request.
- SLOWLOG
- `SLOWLOG GET 10` lists the last ten commands slower than 10 ms, to help find slow commands. `redis-cli --latency` shows reply times until Ctrl+C.
- Snapshot
- A point-in-time copy of all Redis data written to disk by RDB.
- Sorted set
- A set where each member has a number, its score, and members stay ordered by it. Kettle & Crane uses one for best sellers.
- Stale data
- A cached copy that no longer matches the real data, such as a menu showing $72 after Jo changed the price to $74.
- Stale-while-revalidate
- Serving the old copy a little longer while one request rebuilds a fresh one in the background. Nobody waits, but some see slightly old data.
- Stream
- An append-only log in Redis where entries stay in order and many readers can replay them. Each entry gets a time-based id.
- String
- Redis's basic value type: text, JSON, or a number written as text.
T
- TLS
- Encryption for network connections, as HTTPS uses. node-redis uses it when the URL starts with `rediss://`.
- Transaction
- A group of commands run together with no other client's commands in between. In Redis you start one with `MULTI` and run it with `EXEC`.
- trustProxy
- A Fastify option that makes `request.ip` read the real client's address from the `X-Forwarded-For` header. Behind a load balancer, every request would otherwise seem to come from the balancer.
- TTL (time to live)
- How long a key has left before Redis deletes it on its own. `TTL` returns -1 for no expiry and -2 for no such key.
V
- Valkey
- An open source fork of Redis, run by the Linux Foundation, that understands the same commands.
- Versioned keys
- Keys with a version number in the name, such as `kc:menu:v0`. One `INCR` of the version retires every old key at once.
W
- Worker
- A separate program that takes jobs off a queue and does them, such as sending receipt emails.
- Write-behind
- A pattern that writes only to the cache and saves to the database later, in batches. It is fast, but data is lost if Redis fails first, so it suits page-view counts and never orders.
- Write-through
- A pattern where every change updates the database and then writes the fresh value to the cache, so the next read is a hit with the new data.
- WRONGTYPE
- The error Redis gives when you use a command for one data type on a key holding another. The `TYPE` command shows what a key holds.
X
- X-Cache header
- A custom HTTP response header set to `HIT` or `MISS` to show whether a response came from the cache or had to be loaded from the database. It lets you check cache behavior with a tool like `curl -i`.