Redis Basics: In-Memory Database Concepts, Data Structures, and Common Use Cases
This article introduces Redis as an in‑memory key‑value database, explains its five core data structures, and outlines typical scenarios such as caching hot data, counters, queues, bit‑maps for massive datasets, latest‑list feeds, and leaderboards, providing practical guidance for developers.
1. Fundamentals
In-Memory Database
Redis is a key‑value store where each key maps to a single value, and all data resides in memory for high performance. The amount of data a single Redis instance can hold depends on the available RAM, and data can be persisted to disk to survive restarts.
Data Structures
Redis supports five native data structures:
String : the simplest type, storing up to 512 MB per key.
Hash : a collection of field‑value pairs, ideal for representing objects.
List : an ordered list of strings implemented as a doubly‑linked list, useful for feeds or message queues.
Set : an unordered collection of unique strings, supporting set operations such as intersection, union, and difference.
Zset (Sorted Set) : like a Set but each member has an associated score, enabling automatic ordering for leaderboards and ranking.
2. Common Redis Application Scenarios
Cache – Hot Data
Redis is often used to cache frequently read but rarely modified data, offering high QPS and durability options (AOF, RDB). When integrating with frameworks like Spring, developers typically check Redis before querying the database and invalidate the cache on updates, taking care to handle high‑concurrency edge cases.
Counters
Because Redis processes commands single‑threadedly, incrementing counters (e.g., page views) is atomic and millisecond‑level fast.
Queues
Redis lists can act as simple message queues or stacks, allowing sequential processing of concurrent requests and providing position information for ordering.
Bit Operations (Big Data Processing)
For billions‑scale datasets, Redis bitmaps (using SETBIT , GETBIT , BITCOUNT ) enable compact storage of flags such as user sign‑ins or online status, avoiding the memory explosion of one key per user.
Latest List
To serve a constantly updating feed (e.g., news), developers can push items onto a Redis list with LPUSH and fall back to a relational database to rebuild the list when memory is cleared.
Leaderboard
Sorted sets provide an efficient way to maintain ranking tables, automatically ordering members by score.
3. References
https://baijiahao.baidu.com/s?id=1636565352949240200
https://www.cnblogs.com/NiceCui/p/7794659.html
Selected Java Interview Questions
A professional Java tech channel sharing common knowledge to help developers fill gaps. Follow us!
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.