An In-Memory Data Structure Store
Wordcraft is a small online word game. Its player profiles live in a normal SQL database, but every screen also shows a live score, a visit counter and a top-ten board. Asking the main database for those numbers hundreds of times a second is slow and wasteful. Redis is the tool built for exactly that kind of tiny, constant question.
The rule
Every key lives in RAM, and every value is a ready-made structure.
The rule has two halves.
In memory. A classic database keeps its data on disk and pulls pages into memory when needed. Redis turns that around: the whole dataset sits in RAM all the time. Reading from memory takes well under a microsecond, while even a fast SSD needs tens of microseconds, so most Redis commands finish in a tiny fraction of a millisecond. The cost is size: everything must fit in the server's memory.
Data structures. Redis is a key-value database: every piece of data has a name, the key, and you always reach it through that name. What makes Redis different from a plain key-value box is the value. It is not just a blob of bytes but one of several structures Redis understands:
SET wordcraft:visits 41 # string
HSET player:asha name Asha level 6 # hash: named fields
LPUSH feed:asha won # list: ordered items
SADD badges:asha first-win # set: unique members
ZADD leaderboard 320 asha # sorted set: members with scoresBecause Redis knows the shape, it can work inside the value: add one to a counter, append to a list, or return the top three scores, without sending the whole value back to your app first.
Not only a cache. Memory is wiped when a server restarts, so Redis can also write its data to disk: a periodic snapshot (RDB) or a log of every write (AOF, the append-only file). Persistence is optional, and it is a safety net rather than the place Redis reads from.
The shortcut
When you meet any Redis feature, ask two questions: Which key? Which structure? The key tells you where the data is; the structure tells you which commands you can use on it.
Which key?
The score is on the leaderboard, so the key is
leaderboard.
The trap is thinking "in-memory" means "temporary". It means served from memory; with persistence turned on, the data also survives a restart.
Drills
Answer fast — trust the rule.
Where does Redis read a key's value from when it answers a command?
Which statement about Redis values is true?
What is the main limit that comes from keeping everything in memory?
A Redis server with AOF enabled restarts. What happens to its keys?
Remember
- Every key lives in RAM, and every value is a ready-made structure.
- Ask "which key, which structure?" and the right commands follow.
- In-memory is about speed, not about losing data: RDB and AOF can persist it.
