What main data types does Redis support?
Redis supports a set of core data structures, each implemented as efficiently as possible for storage and manipulation in RAM. These types are the foundation of everything Redis does.
1. String
The simplest, most basic data type, key-value. It can store text, numbers, JSON, binary data, images, and more.
Example:
SET user:name "Alice"
GET user:nameArithmetic is supported:
INCR counter
DECRBY counter 5A quirk: a string in Redis can be up to 512 MB.
2. List
An ordered collection of strings, like a queue or a stack. Elements can be added and removed from either end.
Example:
LPUSH queue task1
RPUSH queue task2
LPOP queueUses: task queues, event feeds, chats.
3. Set
An unordered set of unique elements. Supports set-theory operations: intersection, union, difference.
Example:
SADD tags "redis" "database" "cache"
SMEMBERS tags
SISMEMBER tags "redis"Uses: storing unique IDs, subscribers, tags.
4. Sorted Set
Like Set, but every element has a score, a number that determines the sort order.
Example:
ZADD leaderboard 1500 "Alice" 1700 "Bob"
ZRANGE leaderboard 0 -1 WITHSCORESUses: rankings, leaderboards, prioritization, top lists.
5. Hash
Holds a set of field-value pairs under a single key. It resembles a mini-object or JSON.
Example:
HSET user:100 name "Alice" age 25
HGET user:100 name
HGETALL user:100Uses: user profiles, configuration, metadata.
6. Bitmap
Lets you store and manipulate individual bits of a string.
Example:
SETBIT users_online 100 1
GETBIT users_online 100
BITCOUNT users_onlineUses: activity tracking, online statistics, boolean flags.
7. HyperLogLog
A structure for the approximate counting of unique elements with minimal memory use (~12 KB).
Example:
PFADD visitors "user1" "user2" "user3"
PFCOUNT visitorsUses: counting unique users, IPs, events.
8. Stream
A log of structured events (like Kafka). Supports message IDs, consumer groups, acknowledgments.
Example:
XADD events * user "Alice" action "login"
XREADGROUP GROUP g1 c1 COUNT 1 STREAMS events >Uses: task queues, events, microservices, logging.
9. Geo (geospatial data)
Lets you store coordinates and run geo-queries (finding nearby points, distances).
Example:
GEOADD shops 30.5 50.4 "ShopA"
GEORADIUS shops 30.5 50.4 10 kmUses: maps, logistics, tracking, "near me" search.
Summary
| Type | Purpose | Example use |
|---|---|---|
| String | Strings, numbers, JSON | Cache, tokens, counters |
| List | Ordered collections | Queues, feeds |
| Set | Unique elements | Subscriptions, tags |
| Sorted Set | Prioritized elements | Rankings, leaderboards |
| Hash | Objects, dictionaries | Profiles, configs |
| Bitmap | Bit-level flags | Online activity |
| HyperLogLog | Counting unique items | Analytics |
| Stream | Event streams | Queues, logging |
| Geo | Geo-coordinates | Distance search |
Redis isn't just a key-value store, it's a set of highly efficient in-memory data structures that can be combined for any scenario, from caching to streaming analytics.
Short Answer
Interview readyA concise answer to help you respond confidently on this topic during an interview.