Redis Data Structures: String, Hash, List, Set, ZSet, and Stream
Fast recall
Quick revision
Core answer
Whether the candidate understands Redis beyond simple string caching and can map data structures to real use cases.
Candidates often default to using String for everything, missing memory savings and richer operations available from Hashes or Sets.
Mention time complexity for each structure's core operations and give a concrete Java/Spring example for at least two structures.
Interview-ready guide
Interview answer
Redis provides six core data structures, and choosing the right one for a given problem is what separates effective Redis usage from treating it as a simple key-value store.
String — the universal type
- String is the most basic type — it holds text, numbers, or binary data up to 512MB;
SET key value EX 3600stores a value with a 1-hour TTL in one command INCRandINCRBYon string values are atomic — which means a rate limiter or counter can be safely incremented from thousands of concurrent clients without a race condition
Hash — for objects with multiple fields
- A Redis Hash maps field names to values within one key —
HSET user:123 name "Alice" email "alice@example.com"stores multiple attributes under one key, allowingHGET user:123 nameto retrieve individual fields without deserializing the whole object - More memory-efficient than storing a serialized JSON string when you need to update individual fields frequently
List — for queues and feeds
- List maintains insertion order;
LPUSHandRPUSHadd to left or right;BRPOPblocks until an item is available — which makes it a natural message queue pattern for background job dispatch
Set and Sorted Set (ZSet)
- Set holds unique members and supports set operations —
SADD,SUNION,SINTER,SDIFF— useful for tags, friend lists, or deduplication - Sorted Set (ZSet) associates each member with a score and keeps members ordered by score — which means
ZADD leaderboard 4500 "alice"thenZREVRANGE leaderboard 0 9returns the top 10 in one command; the natural structure for real-time rankings and scheduled tasks by timestamp
Stream — for event logs
- Stream provides a persistent, ordered log of entries with consumer group semantics — similar to a lightweight Kafka topic, useful for event sourcing, activity feeds, and reliable message delivery with acknowledgment
Redis Data Structures: String, Hash, List, Set, ZSet, and Stream
Direct Answer
Redis offers six primary data structures — String, Hash, List, Set, Sorted Set (ZSet), and Stream — each optimized for specific access patterns. Strings handle simple key-value caching and counters, Hashes model objects efficiently, Lists support queues and stacks, Sets enforce uniqueness, Sorted Sets power leaderboards and range queries, and Streams handle event sourcing. Choosing the right structure directly impacts memory usage and query performance.
Common Mistakes & Pitfalls
Candidates often default to using String for everything, missing memory savings and richer operations available from Hashes or Sets.
Check your understanding
Answer these without looking back at the article.
- How does Redis handle memory for a Hash with fewer than 128 fields vs a large Hash?
- When would you choose a Sorted Set over a List for a queue?
- How do Redis Streams differ from pub/sub?
Related interview prep categories
1Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.