Redis Overview: Features, Data Types, Caching Strategies, Common Pitfalls, Performance, Persistence, Replication, and Sentinel
This article provides a comprehensive introduction to Redis, covering its core characteristics, supported data types, caching usage patterns, typical issues such as consistency, avalanche, penetration and breakdown, performance reasons, eviction policies, persistence options, master‑slave replication, and Sentinel high‑availability mechanisms.
1. Introduction to Redis
Redis is an open‑source, high‑performance, in‑memory key‑value store written in C, commonly used as a database, cache, or message broker, and belongs to the NoSQL family.
2. Key Characteristics
Excellent performance with data stored in memory, supporting up to 100 K QPS.
Single‑threaded but thread‑safe, using non‑blocking I/O multiplexing.
Can serve as a distributed lock.
Supports five primary data structures.
Provides persistence to disk.
Offers publish/subscribe messaging capabilities.
3. Data Types
Redis supports five data types—strings, hashes, lists, sets, and sorted sets—each suited to different usage scenarios.
4. Caching in Spring Boot
Two typical integration methods are direct usage of RedisTemplate and Spring Cache annotations.
5. Common Caching Problems
(1) Data Consistency
In distributed environments, cache‑database consistency is hard to guarantee; strategies such as cache‑update after DB writes or retry mechanisms are used to mitigate inconsistency.
(2) Cache Avalanche
If the cache crashes, all traffic falls back to the database, potentially overwhelming it; solutions include high‑availability Redis clusters, local Ehcache with rate limiting, and graceful degradation.
(3) Cache Penetration
When requests query keys that do not exist in both cache and DB, attackers can overload the database; mitigations involve request validation, Bloom filters, and storing negative results in Redis.
(4) Cache Breakdown
Hot keys that expire simultaneously cause a surge of DB queries; solutions depend on data change frequency, ranging from never‑expiring hot keys to distributed locks or proactive cache refresh.
6. Why Redis Is Fast
Hash‑map‑like O(1) operations performed entirely in memory.
Simple KV data structures.
Single‑threaded model eliminates lock contention and context switches.
Non‑blocking I/O with multiplexing.
7. Eviction Policies
volatile‑* policies evict only expired keys.
allkeys‑* policies consider all keys.
LRU (Least Recently Used) and LFU (Least Frequently Used) are supported.
Policies trigger when Redis memory reaches the configured threshold.
8. Persistence Mechanisms
RDB : Periodic snapshots saved to a dump file.
AOF : Append‑only file that logs every write command.
Both can be enabled; on restart, AOF is preferred for minimal data loss.
9. Master‑Slave Replication
Slaves execute SLAVEOF to record master info, establish socket connections, exchange PING/PONG, and receive data synchronization; thereafter, masters stream write commands to slaves to keep data consistent.
10. Sentinel Mode
Sentinel monitors master and slave health, sends notifications, performs automatic failover by promoting a slave to master, and acts as a configuration provider for clients.
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.
Architect
Professional architect sharing high‑quality architecture insights. Topics include high‑availability, high‑performance, high‑stability architectures, big data, machine learning, Java, system and distributed architecture, AI, and practical large‑scale architecture case studies. Open to ideas‑driven architects who enjoy sharing and learning.
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.
