Redis & Caching (50 Qs)•Part 1: Basic & Foundational Concepts (Junior / Entry-Level)
What are the core Redis Data Structures and their primary use cases?
junior LevelCode ExampleredisBasic
In Simple Words:
- String: Basic text or binary blob up to 512 MB (caching JSON, session tokens, atomic integer counters with
INCR). - Hash: Key-value map representing an object (e.g. user profile attributes:
name,email,age). - List: Linked list of strings ordered by insertion (job queues, activity feeds with
LPUSH/RPOP). - Set: Unordered collection of unique strings (tagging, unique visitor tracking with
SADD,SINTER). - Sorted Set (ZSET): Unique elements ordered by a floating-point score (real-time leaderboards, rate limiters with
ZADD,ZRANGEBYSCORE). - Bitmap & HyperLogLog: Bit-level operations (daily active users) and probabilistic cardinality estimation with < 1% error using 12 KB of memory.
- Streams: Append-only log with consumer groups (event-driven messaging).
text
Redis Data Types Overview:
┌───────────────┬────────────────────────────┬─────────────────────────────┐
│ Type │ Operations │ Typical Use Case │
├───────────────┼────────────────────────────┼─────────────────────────────┤
│ String │ SET, GET, INCR, DECR │ Page Cache, Token Store │
│ Hash │ HSET, HGET, HGETALL │ User Profiles, Session Data │
│ List │ LPUSH, RPOP, BRPOP │ Task Queues, Feeds │
│ Set │ SADD, SMEMBERS, SINTER │ Unique Visitors, Follows │
│ Sorted Set │ ZADD, ZRANGE, ZREVRANK │ Gaming Leaderboards, Sliders│
│ Stream │ XADD, XREAD, XREADGROUP │ Kafka-like Event Streams │
└───────────────┴────────────────────────────┴─────────────────────────────┘