Redis is an open-source, in-memory data structure store.
Think of it as a super-fast, network-accessible “dictionary” that lives entirely in RAM and can optionally be persisted to disk.
It is not a general-purpose relational database; instead it is optimized for speed and for a handful of specialized data types (strings, lists, sets, sorted sets, hashes, bitmaps, hyper-log-logs, streams, geospatial indexes, JSON, etc.).
Why a developer might pick Redis instead of (or in addition to) another database:
-
Micro-second latency at scale
Because everything is in RAM and single-threaded for core operations, simple reads/writes are typically 50–200 µs—orders of magnitude faster than disk-based SQL or even SSD-backed NoSQL systems.
-
Native data structures
You can push/pop from a list, increment a counter, union two sets, or query a leaderboard by score in a single command. In a traditional DB you would need multiple round-trips or complex SQL.
-
Built-in patterns that are painful elsewhere
• Caching with automatic TTL eviction
• Pub/Sub messaging or lightweight queues
• Rate limiting (token bucket via INCR/EXPIRE)
• Distributed locks (SET NX PX)
• Real-time analytics (HyperLogLog for unique counts, sorted sets for top-N)
• Session storage, shopping-cart data, game leaderboards, etc.
-
Atomic, single-command operations
Every Redis command is atomic, so you can implement safe counters, locks, or queues without transactions or stored procedures.
-
Optional persistence & replication
You can turn on AOF (append-only file) or RDB snapshots so the data survives restarts, and you can replicate to slaves for HA. This lets you treat Redis as a fast “system of record” for transient but valuable data.
-
Simple operations model
No schema migrations, no query planner, no ORM impedance mismatch—just key → data structure.
Typical “versus” decisions
• Versus PostgreSQL/MySQL: Use Redis when you need raw speed, simple access patterns, or ephemeral data; keep SQL when you need complex queries, joins, strict consistency, or large data sets that don’t fit in RAM.
• Versus MongoDB/Dynamo/Cassandra: Use Redis when the working set is small enough for memory and you want micro-second ops; use the others when you need TB-scale durable storage, flexible documents, or multi-region replication.
• Versus Memcached: Redis is usually preferred because it offers the same in-memory caching plus richer data types, persistence, replication, and Lua scripting.
In short, developers choose Redis when the primary requirement is “make this specific operation extremely fast and simple,” and they are willing to trade disk capacity and complex querying for that speed and simplicity.