What are the different data structures supported by Redis?
Updated Feb 20, 2026
Short answer
Redis supports several built-in data structures designed for different access patterns: String, List, Set, Sorted Set, Hash, Stream, Bitmap, HyperLogLog, and Geospatial. Choosing the right structure depends on whether you need fast lookups, ordering, uniqueness, counting, messaging, or approximate analytics.
Deep explanation
Redis is an in-memory data store, but it is more than a simple key-value cache. The value stored under a key can have a rich structure, and each structure provides specialized commands optimized for common application patterns.
The key interview point: Redis data types are not just storage formats; they define the operations Redis can perform efficiently.
Core Redis data structures
| Data Structure | Stores | Common Uses |
|---|---|---|
String | Text, numbers, binary data | Caching, counters, tokens |
List | Ordered collection of values | Queues, recent items |
Set | Unique unordered values | Tags, memberships |
Sorted Set | Unique values with scores | Leaderboards, rankings |
Hash | Field-value pairs | Objects, profiles |
Stream | Append-only event entries | Event processing, messaging |
1. String
The String type is Redis's simplest and most commonly used structure. A string value can store text, integers, serialized objects, or binary data.
Redis provides atomic operations such as INCR, making strings useful for counters.
SET page_views 100INCR page_viewsGET page_viewsAfter INCR, the value becomes 101.
Common examples:
- Session tokens
- Cached API responses
- Feature flags
- Rate-limit counters
2. List
A Redis List is an ordered sequence of strings. It supports insertion and removal from both ends, making it suitable for queue-like workloads.
LPUSH jobs "email_1"LPUSH jobs "email_2"RPOP jobsThe list can behave like:
- A queue (
LPUSH+RPOP) - A stack (
LPUSH+LPOP)
3. Set
A Redis Set stores unique, unordered values. It is optimized for checking membership and performing set operations.
Example:
SADD users:online "alice"SADD users:online "bob"SISMEMBER users:online "alice"Useful operations include:
- Intersection: common items between sets
- Union: combine sets
- Difference: items missing from another set
4. Sorted Set
A Sorted Set (also called ZSet) is similar to a set, but every member has an associated score. Redis automatically keeps members ordered by score.
Use Sorted Sets whenever you need ranking or priority ordering.
Example:
ZADD leaderboard 2500 "player1"ZADD leaderboard 3000 "player2"ZRANGE leaderboard 0 -1 WITHSCORESA leaderboard can quickly retrieve the highest-scoring players.
5. Hash
A Redis Hash stores multiple field-value pairs under one key. It resembles a small object or dictionary.
HSET user:1001 name "Alex" role "admin"HGET user:1001 nameHashes are commonly used for:
- User profiles
- Product information
- Configuration objects
6. Stream
Redis Stream is an append-only log structure designed for event data. It supports consumer groups, allowing multiple applications to process messages independently.
Typical uses:
- Message queues
- Activity feeds
- Event-driven systems
Specialized structures
Redis also provides specialized data types:
- Bitmap: Stores bits inside strings. Useful for compact boolean tracking, such as daily user activity.
- HyperLogLog: Estimates the number of unique items using very little memory. Useful for approximate analytics.
- Geospatial indexes: Store location coordinates and query nearby points.
Redis structures are optimized around operations, not just data representation. The best choice depends on the questions your application needs to answer.
| Requirement | Best Redis Structure |
|---|---|
| Store a simple value | String |
| Maintain a queue | List or Stream |
| Find unique members | Set |
| Rank users by score | Sorted Set |
| Store object fields | Hash |
Real-world example
Imagine building an online gaming platform. Player profiles can be stored as Hash values, current scores as Sorted Sets, and active sessions as Strings with expiration.
HSET player:42 name "Maya" level 15ZADD game:leaderboard 9850 "player:42"SET session:abc123 "player:42" EX 3600The application can quickly fetch a player's profile, show the top players, and automatically expire inactive sessions.
This works well because each Redis structure matches a specific access pattern instead of forcing all data into one format.
Common mistakes
- * **Using Strings for everything** - A single serialized object may work initially but loses Redis's built-in operations. Use `Hash`, `Set`, or `Sorted Set` when their operations match the problem.
- * **Ignoring memory trade-offs** - Some structures consume more memory than others. Choose compact structures like `HyperLogLog` when exact storage is unnecessary.
- * **Confusing Sets and Sorted Sets** - Sets provide uniqueness
- Sorted Sets provide uniqueness plus ordering through scores.
- * **Treating Redis Lists as full databases** - Lists are excellent for queues but are not designed for complex querying or durable storage.
Follow-up questions
- What is the difference between a Redis Set and Sorted Set?
- Why are Redis Streams preferred over Lists for event processing?
- How does Redis expire cached data?
- When would you use HyperLogLog instead of a Set?