What Is Redis? How Does Redis Work?
What problem does Redis solve?
Imagine an online store. Every time a customer opens a product page, the server may query the main database to retrieve the same product information. If many customers request that product, the database repeats similar work.
Redis can keep a temporary copy of frequently used information in memory. The application can check Redis first and query the main database only when the cached value is missing or no longer valid.
What is Redis?
Redis is an in-memory data store. Applications send commands to a Redis server, and the server returns results. Redis is commonly used for caching, counters, sessions, rate limiting, and other workloads that benefit from fast access to data.
A Redis key identifies a value. For example, product:42 can be the key for product 42. Redis supports several value types, including strings, hashes, lists, sets, and sorted sets—not just plain text.
How does a request work?
1. A Node.js API receives a request for product 42.
2. The API asks Redis for product:42.
3. If Redis has a usable value, the API returns it.
4. If the value is missing, the API queries the primary database.
5. The API may save the result in Redis for later requests.
Redis is usually an additional layer, not a replacement for the main database. It can also persist data to disk when configured to do so, so “in-memory” does not mean persistence is impossible.
Try your first commands
Open redis-cli against a running Redis server and enter:
PING
SET course:name "Redis Basics"
GET course:nameExpected replies:
PONG
OK
"Redis Basics"PING checks that Redis responds. SET stores a string under a key. GET retrieves the value for that key.
Key takeaways
- Redis is an in-memory data store with multiple data structures.
- Applications communicate with Redis using commands.
- Redis often works alongside a primary database.
- Redis can be configured for persistence, but the configuration matters.
Hands-on task
Store your name under learner:name, retrieve it, and explain in two sentences how a product API could use Redis. If you do not have Redis installed yet, complete this task after Lesson 4.