Redis
Remote Dictionary Server
- Pronunciation
- RED-iss
In short
Redis is an in-memory key-value store that reads and writes in well under a millisecond, which makes it a popular cache, session store and message broker.
What is Redis?
Redis, short for Remote Dictionary Server, was created by Salvatore Sanfilippo in 2009. It stores data as keys and values, like a giant dictionary, but the values can be rich data structures: strings, lists, sets, sorted sets, hashes, streams and more. Because everything lives in memory instead of on disk, most operations finish in microseconds.
Applications talk to Redis with simple commands such as SET, GET, INCR or EXPIRE. A key can be given a time to live, after which Redis deletes it on its own, which is exactly what a cache or a login session needs. Redis can also save snapshots or an append-only log to disk, so data survives a restart, and it can replicate to other servers for high availability.
Typical uses are caching database results, storing user sessions, counting things such as page views or rate-limit hits, leaderboards built on sorted sets, and lightweight queues or pub/sub messaging between services. In many systems it sits next to a main database like PostgreSQL, holding the hot data that is read again and again.
A common misconception is that Redis is only a cache. It is a full data store, but its data must fit in memory, which is more expensive than disk, so it is rarely the only database an application has. Since 2024 its license has changed more than once, and the Linux Foundation maintains an open-source fork called Valkey that works with the same commands.
At a glance
Key takeaways
- Redis is an in-memory key-value store, so reads and writes are extremely fast.
- Values can be strings, lists, sets, sorted sets, hashes and streams.
- Keys can expire automatically, which suits caches and sessions.
- Data can be saved to disk and replicated to other servers.
- It usually works next to a main database rather than replacing it.
Example
import { createClient } from "redis";
const redis = createClient();
await redis.connect();
// Store a value that Redis deletes after 60 seconds
await redis.set("user:42:name", "Ada", { EX: 60 });
const name = await redis.get("user:42:name"); // "Ada"
await redis.incr("page:home:views"); // atomic counterReaders ask
Is Redis a database or a cache?
Both. Redis is a data store that can keep data permanently, but because its data lives in memory it is most often used as a cache or for short-lived data next to a main database.
What happens to Redis data when the server restarts?
Without persistence it is lost. With snapshots (RDB) or an append-only file (AOF) turned on, Redis reloads the data from disk when it starts again.
What is Valkey?
Valkey is an open-source fork of Redis maintained under the Linux Foundation, started in 2024 after Redis changed its license. It works with the same commands and client libraries.
See also
- Key-Value StoreDatabases, p. 25A key-value store is a NoSQL database that saves each piece of data under a unique key, so an application can read or write it by that key very quickly.
- CacheBackend & APIs, p. 8A cache is a fast, temporary storage layer that keeps copies of frequently used data so later requests can be served quickly without repeating slow work.
- NoSQLDatabases, p. 29NoSQL is a family of databases that store data in models other than relational tables, such as documents, key-value pairs, wide columns, or graphs.
- SessionBackend & APIs, p. 43A session is a way for a server to remember a user across many requests, usually by keeping their data on the server and giving the browser a session ID.
- Rate LimitingBackend & APIs, p. 37Rate limiting is a technique that caps how many requests a client can make to a server or API within a time window, protecting it from abuse and overload.
- Pub/SubBackend & APIs, p. 35Pub/sub is a messaging pattern where publishers send messages to topics and every subscriber to a topic gets a copy, without either side knowing the other.
- LuaProgramming Languages, p. 19Lua is a small, fast scripting language designed to be embedded in other applications, making it popular for game scripting, plugins and configuration.
Sources
Spotted a mistake or something missing on this page?Suggest an edit