Overview
- 1Redis (Remote Dictionary Server) is an open-source, in-memory data structure store that doubles as a database, cache, message broker, and streaming engine.
- 2Unlike a plain cache, Redis supports rich data types — strings, hashes, lists, sets, sorted sets, and streams — with atomic operations on each.
- 3Data lives primarily in RAM for sub-millisecond latency, with optional persistence to disk via RDB snapshots and/or append-only file (AOF) logging.
- 4Redis 8.0 reunified the project under an open-source AGPLv3 license (alongside RSALv2/SSPLv1 options), after the 2024 licensing change spurred the Linux Foundation-backed Valkey fork.
- 5It runs command execution on a single-threaded event loop for predictable performance, while I/O threading and Redis Cluster provide horizontal scale-out.
Key Features in 8.0
Rich data structures: strings, hashes, lists, sets, sorted sets, streams, bitmaps, HyperLogLog, and geospatial indexes.
Sub-millisecond read/write latency from in-memory storage, with O(1) or O(log N) complexity on most commands.
Persistence options — RDB point-in-time snapshots and AOF write-ahead logging — for durability and crash recovery.
Built-in replication (leader-follower) plus Redis Sentinel for automated monitoring and failover.
Redis Cluster for horizontal sharding across up to 16,384 hash slots with online resharding.
Pub/Sub messaging and Redis Streams with consumer groups for real-time and event-driven pipelines.
Extensibility via modules (RedisJSON, RediSearch/vector search, RedisTimeSeries, RedisBloom) and server-side Redis Functions.
Use Cases
- →Application-layer caching in front of relational or document databases to cut read latency and database load.
- →Session storage, token blacklists, and rate-limit counters for web and API backends.
- →Real-time leaderboards and ranking using sorted sets, plus approximate analytics with HyperLogLog and bitmaps.
- →Message brokering and task queues via Pub/Sub or Streams, and distributed locks for cross-service coordination.
Core Data Structures
- Strings: simple key-value pairs, atomic counters (INCR/DECR), and binary-safe values up to 512MB.
- Hashes: field-value maps well suited to representing objects like user profiles without full JSON serialization.
- Lists: linked lists with push/pop from either end, commonly used for queues and activity feeds.
- Sets and Sorted Sets: unique unordered or score-ordered collections; sorted sets power leaderboards and range queries.
- Streams: append-only logs with consumer groups for durable, at-least-once event processing.
- Bitmaps and HyperLogLog: space-efficient structures for flag storage and probabilistic unique-count estimation.
- Vector sets (Redis 8.0+): a native data type for storing embeddings and running approximate nearest-neighbor search.
Persistence, Caching & Eviction
- RDB snapshots: compact point-in-time binary dumps that restart quickly, saved at configurable intervals.
- AOF (append-only file): logs every write for finer durability, with background rewrite to keep file size in check.
- Hybrid persistence combines RDB snapshots with AOF for faster restarts alongside stronger durability guarantees.
- Eviction policies (LRU, LFU, TTL-based, random) let Redis behave as a bounded cache once maxmemory is reached.
- Key expiration (TTL) automatically cleans up sessions, cache entries, and rate-limit windows.
- Transactions via MULTI/EXEC, with optimistic locking through WATCH for check-and-set style updates.
- Lua scripting (EVAL) and Redis Functions allow atomic, server-side multi-command logic.
Pub/Sub, Streams & Messaging
- Pub/Sub channels provide lightweight, fire-and-forget broadcast messaging between publishers and subscribers.
- Sharded Pub/Sub (Redis 7+) spreads channel traffic across cluster shards for better scalability.
- Redis Streams (XADD/XREAD/XRANGE) act as an append-only log, similar in spirit to a lightweight Kafka topic.
- Consumer groups on streams let multiple workers share message processing with acknowledgment (XACK) and replay.
- Client-side caching with tracking invalidation lets clients cache reads locally and get notified when data changes.
- Keyspace notifications let applications react to expirations, deletions, and writes on watched keys.
- Redis commonly backs job queues, paired with libraries like BullMQ, Sidekiq, or Celery's Redis broker.
Scaling, Security & Ecosystem
- Redis Cluster shards data across nodes using 16,384 hash slots, supporting resharding without downtime.
- Redis Sentinel monitors primary/replica deployments and orchestrates automatic failover for high availability.
- ACLs (access control lists) provide fine-grained, per-user command and key-pattern permissions since Redis 6.
- TLS encryption in transit and RESP3 protocol support enable richer, more secure client-server communication.
- Managed offerings — Redis Cloud, AWS ElastiCache, Azure Cache for Redis, Google Memorystore — handle operations and scaling.
- Valkey, the Linux Foundation-backed fork maintained by AWS, Google, and others, offers a drop-in-compatible open-source alternative.
- Client libraries across virtually every language (redis-py, ioredis, node-redis, Jedis/Lettuce, StackExchange.Redis) keep integration straightforward.
Frequently Asked Questions
What is Redis used for?▼
Redis is most commonly used as an in-memory cache in front of slower databases, but it's also used as a session store, rate limiter, real-time leaderboard engine, pub/sub message broker, and lightweight queue via Redis Streams. Because data lives in RAM, it's well suited to workloads needing sub-millisecond latency and high throughput.
Is Redis a database or a cache?▼
Redis is both — at its core it's an in-memory key-value data store with optional persistence via RDB snapshots and AOF logging, which makes it a legitimate primary database for some workloads. Its speed, TTL support, and eviction policies also make it an excellent cache layer, and most teams use it primarily that way.
Redis vs Memcached — which should I choose?▼
Memcached is a simpler, multi-threaded pure cache limited to string values, while Redis supports richer data structures (hashes, lists, sorted sets, streams), persistence, replication, and pub/sub. Choose Memcached for a dead-simple, horizontally scaled cache with minimal operational overhead; choose Redis when you need data structures, durability, or messaging beyond basic key-value caching.
What is the difference between Redis and Valkey?▼
In March 2024, Redis Ltd. changed Redis's license from BSD to source-available terms (SSPLv1/RSALv2), prompting the Linux Foundation and cloud providers including AWS, Google, and Oracle to launch Valkey as an open-source fork of the last BSD-licensed Redis codebase. Redis Ltd. later reintroduced an open-source AGPLv3 license option starting with Redis 8.0, so both projects are now open source but developed independently, with largely compatible commands and protocols.
How does Redis persistence work if it's an in-memory store?▼
Redis can write data to disk two ways: RDB snapshots, which save a compact binary dump of the dataset at configured intervals, and AOF, which logs every write command for replay on restart. Many deployments combine both for fast restarts via RDB plus minimal data loss via AOF; persistence can also be disabled entirely for pure-cache use cases.
How does Redis handle scaling and high availability?▼
Redis Cluster shards data across multiple nodes using 16,384 hash slots, allowing horizontal scaling with online resharding. Redis Sentinel monitors primary/replica deployments and performs automatic failover if the primary goes down, and managed offerings like Redis Cloud, AWS ElastiCache, and Azure Cache for Redis handle both concerns automatically.