What Redis is and how it works
Redis is an in-memory data structure store. Each key holds a value of one type: string, hash, list, set, sorted set, stream or JSON. Commands run in fractions of a millisecond because the data lives in RAM.
When Redis is a good fit
Redis suits small data that must be accessed fast and can be rebuilt if needed:
- caching of query results and pages;
- user sessions with a key time to live (TTL);
- counters and rate limiting;
- job queues and event streams;
- rankings and leaderboards built on sorted sets.
Redis is not suitable as the only store for data you cannot afford to lose: even with persistence enabled, the last few commands may not reach the disk. Your data must also fit in the server’s memory: beyond the limit, Redis either evicts keys or refuses writes. Keep your primary data in a relational database and run Redis alongside it.
How Redis processes commands
A single thread serves commands: it accepts requests from all clients through multiplexing and executes them strictly one at a time. This makes every command atomic and removes the need for locks between clients. The downside is that a command that walks a large collection delays every other client. Redis uses background threads only for slow I/O operations, such as disk work.
Where the data is stored
The working set is always in memory. To survive a restart, Redis can periodically save a snapshot of the whole dataset (RDB) or append every write command to a log (AOF); the modes can be combined or disabled. For details, see the section “Persistence: RDB and AOF”. Copies of the data on other servers are replicas; they are covered in the section “Replication, Sentinel and Cluster”.
How it differs from Valkey and Kafka
In March 2024 Redis changed its licence, and the community created the Valkey fork under the Linux Foundation. A comparison based on the documentation of both projects:
| Aspect | Redis Open Source | Valkey |
|---|---|---|
| Origin | the original project, led by Redis Ltd. | a fork of Redis OSS 7.2, a Linux Foundation project |
| Protocol and commands | its own new commands and types | compatible with Redis OSS 7.2 and earlier |
| Licence up to 7.2 | BSD | BSD |
| Licence of newer versions | 7.4 to 7.8: RSALv2 or SSPLv1; 8 and later: also AGPLv3 | BSD |
| New features | JSON, vector sets and other types are included | the 7.2 fork evolves independently, with its own releases |
| Where to get it | redis.io, GitHub redis/redis, Docker images | valkey.io, GitHub valkey-io/valkey |
For most applications, clients work with both servers in the same way as long as you stick to the Redis features available up to 7.2. Commands and types added later may differ between the projects: check the ones you need in the documentation of the server you choose.
Redis Streams and Kafka solve similar problems, event delivery, but Redis streams are held in the server’s memory, while Kafka is a distributed log on disk; see the Kafka reference for a comparison.
What you should know first
- The Linux command line: files, processes, permissions (see the Linux reference)
- Docker, if you run Redis in a container (see the Docker reference)
Section sources
the section is written from these pages- Diagnosing latency issuesredis.io/docs/latest/operate/oss_and_stack/management/optimization/latency/(opens in a new tab)
- Redis as an in-memory data structure store quick start guideredis.io/docs/latest/develop/get-started/data-store/(opens in a new tab)
- Licensesredis.io/legal/licenses/(opens in a new tab)
- Valkeyvalkey.io(opens in a new tab)