juniorRedis

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 StructureStoresCommon Uses
StringText, numbers, binary dataCaching, counters, tokens
ListOrdered collection of valuesQueues, recent items
SetUnique unordered valuesTags, memberships
Sorted SetUnique values with scoresLeaderboards, rankings
HashField-value pairsObjects, profiles
StreamAppend-only event entriesEvent 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.

redis-cli
SET page_views 100
INCR page_views
GET page_views

After 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.

redis-cli
LPUSH jobs "email_1"
LPUSH jobs "email_2"
RPOP jobs

The 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:

redis-cli
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:

redis-cli
ZADD leaderboard 2500 "player1"
ZADD leaderboard 3000 "player2"
ZRANGE leaderboard 0 -1 WITHSCORES

A 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.

redis-cli
HSET user:1001 name "Alex" role "admin"
HGET user:1001 name

Hashes 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.

Rendering diagram…

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.
RequirementBest Redis Structure
Store a simple valueString
Maintain a queueList or Stream
Find unique membersSet
Rank users by scoreSorted Set
Store object fieldsHash

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.

redis-cli
HSET player:42 name "Maya" level 15
ZADD game:leaderboard 9850 "player:42"
SET session:abc123 "player:42" EX 3600

The application can quickly fetch a player's profile, show the top players, and automatically expire inactive sessions.

Rendering diagram…

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?

More Redis interview questions

View all →