Core Data Types
Redis provides several fundamental data types, each with its own set of commands and characteristics:Strings
Binary-safe strings up to 512MB. Used for caching, counters, and distributed locks.
Lists
Ordered collections of strings. Perfect for queues, activity feeds, and stacks.
Sets
Unordered collections of unique strings. Ideal for tags, unique visitors, and relationships.
Sorted Sets
Sets ordered by score. Essential for leaderboards, priority queues, and time series.
Hashes
Field-value maps. Great for objects, user profiles, and counters.
Streams
Append-only log structure with consumer groups. Built for event sourcing and messaging.
Extended Data Types
JSON
Native JSON documents with JSONPath queries. Requires BUILD_WITH_MODULES=yes.
Bitmaps
Bit-level operations on strings. Efficient for analytics and permissions.
HyperLogLog
Probabilistic cardinality estimation. Count unique items with minimal memory.
Geospatial
Longitude/latitude coordinates with radius queries. Built on sorted sets.
Choosing the Right Data Type
| Use Case | Recommended Type | Why |
|---|---|---|
| Caching | Strings | Simple get/set with TTL |
| Session storage | Hashes or JSON | Structured data with field updates |
| Counters | Strings | Atomic INCR/DECR operations |
| Rate limiting | Sorted Sets | Time-based windowing |
| Leaderboards | Sorted Sets | Score-based ranking |
| Queues | Lists or Streams | FIFO/LIFO with blocking |
| Real-time feeds | Lists or Streams | Chronological ordering |
| Unique visitors | Sets or HyperLogLog | Uniqueness tracking |
| Tagging | Sets | Set operations (union, intersection) |
| Event sourcing | Streams | Append-only with consumer groups |
| User profiles | Hashes | Object representation |
| Location search | Geospatial | Radius and proximity queries |
Data Type Internals
Redis uses different internal encodings based on data size and type:Memory-Efficient Encodings
- LISTPACK: Compact serialization for small collections (lists, hashes, sorted sets)
- INTSET: Space-efficient integer sets when all members are integers
- ZIPLIST: Legacy compact encoding (deprecated in favor of listpack)
Standard Encodings
- HASHTABLE: Standard hash table for larger datasets
- SKIPLIST: Probabilistic balanced tree for sorted sets
- QUICKLIST: List of listpacks for efficient list operations
- RADIX TREE: Efficient tree structure for streams
Redis automatically selects the most efficient encoding based on the data size and configured thresholds. You can view the encoding with the
OBJECT ENCODING key command.Performance Characteristics
Each data type has different performance characteristics:| Data Type | Read | Write | Range Query | Memory |
|---|---|---|---|---|
| Strings | O(1) | O(1) | N/A | Highest |
| Lists | O(1) ends, O(N) middle | O(1) ends | O(N) | Medium |
| Sets | O(1) | O(1) | N/A | Medium |
| Sorted Sets | O(log N) | O(log N) | O(log N + M) | High |
| Hashes | O(1) field | O(1) field | O(N) | Medium |
| Streams | O(1) append | O(1) | O(N) | Medium-High |
Module Data Types
These require compiling Redis withBUILD_WITH_MODULES=yes:
- JSON: Full-featured JSON document storage
- Time Series: Optimized time-series data with automatic downsampling
- Bloom Filter: Probabilistic set membership
- Cuckoo Filter: Bloom filter with deletion support
- Vector Sets: Embedding vectors for similarity search
Next Steps
Strings
Learn about the most versatile data type
Commands Reference
Explore all available commands