Redis Overview: Features, Data Types, Caching Strategies, Performance, Persistence, Replication, and Sentinel
This article provides a comprehensive introduction to Redis, covering its core features, supported data structures, common caching patterns, typical cache‑related problems and mitigation techniques, performance characteristics, eviction policies, persistence options, replication mechanisms, and Sentinel high‑availability architecture.
Redis is an open‑source, high‑performance, in‑memory key‑value store written in C, often used as a database, cache, or message broker.
Features
Excellent performance with data stored in memory, supporting up to 100K QPS.
Single‑threaded process that is thread‑safe, using I/O multiplexing.
Can be used as a distributed lock.
Supports five primary data types.
Provides data persistence to disk.
Can serve as a message broker with publish/subscribe capabilities.
Data Types
Redis supports five main data structures—strings, lists, sets, sorted sets, and hashes—each suited to different use cases.
Caching
In Spring Boot, Redis is commonly used either directly via RedisTemplate or through Spring Cache annotations.
Cache Issues
Data Consistency
In distributed environments, cache‑DB consistency is difficult; typical strategies include updating the cache immediately after a DB write and implementing retry mechanisms for cache failures.
Cache Avalanche
If the cache crashes, all traffic falls back to the database, potentially causing overload; mitigation includes high‑availability setups (master‑slave + Sentinel or clustering), local Ehcache with rate limiting, and enabling persistence for quick recovery.
Cache Penetration
Requests for non‑existent keys can bypass the cache and hammer the DB; solutions involve request validation, Bloom filters, and caching negative results.
Cache Breakdown
Hot keys that expire can cause a sudden surge of DB requests; solutions include never‑expiring static data, using distributed locks for cache refresh, or proactive cache rebuilding before expiration.
Performance
Redis achieves high throughput by using O(1) hash‑map operations, a simple KV data model, single‑threaded execution that avoids lock contention, and non‑blocking I/O multiplexing.
Eviction Policies
volatile‑* (evicts expired keys)
allkeys‑* (evicts any key)
LRU (least recently used)
LFU (least frequently used)
Persistence
Redis offers two persistence mechanisms: RDB snapshots (periodic dumps of memory to disk) and AOF (append‑only file logging every write command). They can be used together for greater durability.
Replication
Master‑slave replication synchronizes data from the master to slaves and propagates write commands to keep slaves up‑to‑date.
Sentinel
Redis Sentinel provides monitoring, notification, automatic failover, and configuration services to ensure high availability when the master node fails.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Top Architect
Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
