Skip to main content

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:

bash
SET user:name "Alice" GET user:name

Arithmetic is supported:

bash
INCR counter DECRBY counter 5

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

bash
LPUSH queue task1 RPUSH queue task2 LPOP queue

Uses: task queues, event feeds, chats.

3. Set

An unordered set of unique elements. Supports set-theory operations: intersection, union, difference.

Example:

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

bash
ZADD leaderboard 1500 "Alice" 1700 "Bob" ZRANGE leaderboard 0 -1 WITHSCORES

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

bash
HSET user:100 name "Alice" age 25 HGET user:100 name HGETALL user:100

Uses: user profiles, configuration, metadata.

6. Bitmap

Lets you store and manipulate individual bits of a string.

Example:

bash
SETBIT users_online 100 1 GETBIT users_online 100 BITCOUNT users_online

Uses: activity tracking, online statistics, boolean flags.

7. HyperLogLog

A structure for the approximate counting of unique elements with minimal memory use (~12 KB).

Example:

bash
PFADD visitors "user1" "user2" "user3" PFCOUNT visitors

Uses: counting unique users, IPs, events.

8. Stream

A log of structured events (like Kafka). Supports message IDs, consumer groups, acknowledgments.

Example:

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

bash
GEOADD shops 30.5 50.4 "ShopA" GEORADIUS shops 30.5 50.4 10 km

Uses: maps, logistics, tracking, "near me" search.

Summary

TypePurposeExample use
StringStrings, numbers, JSONCache, tokens, counters
ListOrdered collectionsQueues, feeds
SetUnique elementsSubscriptions, tags
Sorted SetPrioritized elementsRankings, leaderboards
HashObjects, dictionariesProfiles, configs
BitmapBit-level flagsOnline activity
HyperLogLogCounting unique itemsAnalytics
StreamEvent streamsQueues, logging
GeoGeo-coordinatesDistance 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 ready
Premium

A concise answer to help you respond confidently on this topic during an interview.