Redis Data Structures Interview Questions
Master Redis Data Structures with interview-focused questions covering Strings, Hashes, Lists, Sets, Sorted Sets, Bitmaps, Bitfields, HyperLogLog, Geospatial Indexes, Streams, TTL, and enterprise production use cases.
Introduction
Redis is often called a Data Structure Server because it provides multiple built-in data structures optimized for different use cases.
Instead of storing everything as plain strings, Redis supports specialized data structures that enable extremely fast operations.
Redis data structures are widely used for
- User Sessions
- Shopping Carts
- Leaderboards
- Chat Systems
- Messaging
- Analytics
- Rate Limiting
- Real-Time Monitoring
- Gaming
- Financial Applications
Understanding these data structures is one of the most common Redis interview topics.
Redis Data Structures Overview
flowchart TD
Redis --> String
Redis --> Hash
Redis --> List
Redis --> Set
Redis --> SortedSet["Sorted Set"]
Redis --> Bitmap
Redis --> Bitfield
Redis --> HyperLogLog
Redis --> Geo
Redis --> Stream
1. What data structures does Redis support?
Answer
Redis supports
- String
- Hash
- List
- Set
- Sorted Set (ZSet)
- Bitmap
- Bitfield
- HyperLogLog
- Geospatial Index
- Stream
Each structure is optimized for different business scenarios.
2. What is a Redis String?
A String is the simplest Redis data structure.
It stores
- Text
- Numbers
- Binary Data
- JSON
- Serialized Objects
Example
SET username "venu"
GET username
String Use Cases
- Cache
- Session
- JWT Token
- OTP
- Configuration
3. What operations are supported on Strings?
Examples
SET
GET
APPEND
INCR
DECR
MSET
MGET
String Example
SET counter 10
INCR counter
GET counter
Result
11
4. What is a Redis Hash?
A Hash stores multiple field-value pairs inside one key.
Example
HSET user:101
name "Venu"
city "San Antonio"
age 35
Hash Structure
user:101
├── name = Venu
├── city = San Antonio
└── age = 35
5. When should Hash be used?
Suitable for
- User Profiles
- Employee Records
- Product Details
- Customer Information
6. Common Hash commands
HSET
HGET
HMGET
HGETALL
HDEL
HEXISTS
7. What is a Redis List?
A List is an ordered collection of values.
Duplicates are allowed.
Useful for
- Queues
- Task Processing
- Recent Activities
List Example
LPUSH orders order1
LPUSH orders order2
RPOP orders
List Structure
Head
↓
Order3
↓
Order2
↓
Order1
↓
Tail
8. Common List commands
LPUSH
RPUSH
LPOP
RPOP
LRANGE
LLEN
9. What is a Redis Set?
A Set stores unique values.
Properties
- No Duplicates
- Unordered
- Fast Membership Lookup
Set Example
SADD skills
Java
Spring
Docker
Set Use Cases
- Tags
- User Roles
- Permissions
- Friend Lists
10. Common Set commands
SADD
SREM
SMEMBERS
SISMEMBER
SUNION
SINTER
11. What is a Sorted Set?
Sorted Set
(ZSet)
stores
Score
+
Value
Scores determine ordering.
Sorted Set Example
ZADD leaderboard
100 Alice
200 Bob
150 Charlie
Sorted Set
200 Bob
150 Charlie
100 Alice
12. Common Sorted Set commands
ZADD
ZRANGE
ZREVRANGE
ZSCORE
ZREM
13. Where are Sorted Sets used?
Examples
- Leaderboards
- Rankings
- Scores
- Trending Products
14. What is Bitmap?
Bitmap stores
bits
instead of objects.
Useful for
- Daily Login Tracking
- Attendance
- Boolean Flags
Bitmap Example
SETBIT login
1001
1
Bitmap
User
↓
Bit
↓
1
Logged In
15. What is Bitfield?
Bitfield stores
multiple counters
inside one string.
Benefits
- Memory Efficient
- Fast
Used in
- Gaming
- Analytics
16. What is HyperLogLog?
HyperLogLog estimates
the number of unique values
using very little memory.
Memory usage remains approximately constant even for millions of elements.
HyperLogLog Example
PFADD visitors
A
B
C
D
PFCOUNT visitors
HyperLogLog Use Cases
- Website Visitors
- Unique Users
- Analytics
17. What is Geospatial Index?
Redis supports
location-based queries.
Example
Store
- Latitude
- Longitude
Search nearby locations.
Geo Example
GEOADD cities
-98.4936
29.4241
SanAntonio
Geo Use Cases
- Food Delivery
- Taxi Booking
- Maps
- Nearby Stores
18. What is a Stream?
Redis Stream is an append-only log data structure.
Supports
- Event Streaming
- Consumer Groups
- Messaging
Introduced in Redis 5.
Stream Architecture
flowchart LR
Producer --> RedisStreamConsumerGroup["Redis Stream --> Consumer Group --> Consumer1"]
ConsumerGroup["Consumer Group"] --> Consumer2
19. Common Stream commands
XADD
XREAD
XGROUP
XACK
20. What are Consumer Groups?
Consumer Groups allow
multiple consumers
to process messages
without duplication.
21. What is TTL?
TTL
(Time To Live)
defines
how long
a key remains
before automatic deletion.
TTL Example
SET otp 123456
EXPIRE otp 300
22. What is key expiration?
Expired keys
are automatically removed
by Redis.
Useful for
- Sessions
- OTPs
- Tokens
TTL Workflow
flowchart LR
SetKey["SET Key"] --> TtlExpirationDelete["TTL --> Expiration --> Delete"]
23. Banking Example
Customer Session
↓
Hash
↓
TTL
↓
Automatic Logout
24. E-Commerce Example
Shopping Cart
↓
Hash
↓
Expiration
↓
Inactive Cart Removed
25. Gaming Example
Leaderboard
↓
Sorted Set
↓
Top Players
↓
Milliseconds
26. Analytics Example
Unique Visitors
↓
HyperLogLog
↓
Millions of Users
↓
Constant Memory
27. Ride Sharing Example
Nearby Drivers
↓
Geo Index
↓
Fast Search
28. Messaging Example
Order Events
↓
Redis Streams
↓
Consumer Groups
↓
Microservices
29. Common Mistakes
- Using Strings for everything
- Ignoring TTL
- Using Lists instead of Streams
- Using Sets when ordering is required
- Large Hashes without expiration
- No memory monitoring
Redis Data Structure Selection
flowchart TD
Requirement --> SimpleValue
SimpleValue --> String
Requirement --> Object
Object --> Hash
Requirement --> Queue
Queue --> List
Requirement --> UniqueItems
UniqueItems --> Set
Requirement --> Ranking
Ranking --> SortedSet
Requirement --> Messaging
Messaging --> Stream
Enterprise Best Practices
- Use Strings for simple values.
- Use Hashes for objects.
- Use Lists for queues.
- Use Sets for uniqueness.
- Use Sorted Sets for rankings.
- Use Streams for messaging.
- Configure TTL for temporary data.
- Monitor memory consumption.
- Choose the right structure based on access patterns.
- Benchmark before production deployment.
Quick Revision
| Data Structure | Use Case |
|---|---|
| String | Cache, OTP, Token |
| Hash | User Profile |
| List | Queue |
| Set | Unique Items |
| Sorted Set | Leaderboard |
| Bitmap | Login Tracking |
| Bitfield | Counters |
| HyperLogLog | Unique Count |
| Geo | Location Search |
| Stream | Messaging |
Interview Tips
Interviewers frequently ask
- Why is Redis called a Data Structure Server?
- String vs Hash.
- List vs Stream.
- Set vs Sorted Set.
- When should Hash be used?
- What is HyperLogLog?
- What is Bitmap?
- What are Consumer Groups?
- What is TTL?
- Which Redis data structure would you choose for a leaderboard?
A strong interview explanation is:
"Redis provides multiple specialized data structures, each optimized for a specific workload. Strings are ideal for caching and tokens, Hashes for objects, Lists for queues, Sets for unique collections, Sorted Sets for rankings, Bitmaps for boolean tracking, HyperLogLog for approximate unique counting, Geo indexes for location searches, and Streams for reliable event-driven messaging. Choosing the right data structure significantly improves performance and memory efficiency."
Summary
Redis offers a rich collection of high-performance data structures that go far beyond simple key-value storage. Features such as Strings, Hashes, Lists, Sets, Sorted Sets, Bitmaps, HyperLogLog, Geospatial Indexes, and Streams enable developers to build scalable, low-latency enterprise applications for caching, messaging, analytics, and real-time processing.
A solid understanding of Redis data structures and their appropriate use cases is essential for Backend Developers, Microservices Engineers, DevOps Engineers, Database Engineers, and Solution Architects working with modern distributed systems.