Databases 30 min read

Redis Data Types Overview and Internal Implementations

An extensive guide to Redis data structures—including strings, hashes, lists, sets, sorted sets, streams, hyperloglog, geospatial, bitmap, and bitfield—detailing their use cases, underlying encodings, conversion thresholds, and internal implementation details with code examples.

Top Architect
Top Architect
Top Architect
Redis Data Types Overview and Internal Implementations

Redis is a high‑performance, open‑source key‑value store that supports a variety of data types. This article provides a comprehensive overview of the ten primary Redis data structures, their typical application scenarios, and the internal encoding mechanisms Redis uses to balance memory usage and speed.

String

The most basic type, capable of storing up to 512 MB. Internally implemented with SDS (simple dynamic string) and three encodings: embstr , raw , and int . embstr is used for strings ≤44 bytes, raw for larger strings, and int for integer values.

Typical uses include caching, counters, distributed locks, and rate limiting.

Hash

Stores a map of field‑value pairs, similar to a programming language map. Depending on size, Redis chooses between ziplist / listpack and a regular hashtable . Thresholds are controlled by hash-max-ziplist-entries and hash-max-ziplist-value .

Commonly used for user profiles, shopping carts, and configuration objects.

List

An ordered collection of strings. Implementations evolved from linkedlist and ziplist to quicklist (a hybrid of linked list and ziplist) and finally to listpack in newer Redis versions. Lists are ideal for queues, timelines, and history logs.

Set

An unordered collection of unique strings. Encodings switch between intset (for small integer sets) and hashtable . Since Redis 7.2 a listpack encoding is also used for medium‑sized sets.

Typical scenarios include deduplication, set operations (union, intersection, difference), and random sampling.

Sorted Set (ZSet)

Stores unique strings with a floating‑point score, enabling ordered retrieval. Small collections use listpack (or ziplist pre‑7.0); larger ones use a skiplist for O(log N) operations.

Commonly used for leaderboards, delayed queues, and ranking systems.

Stream

A log‑like data structure where each entry has a unique ID. Internally backed by a radix tree ( rax ) for ID indexing and listpack for entry payloads.

Used for event sourcing, message queues, and change logs.

HyperLogLog

A probabilistic structure for cardinality estimation, stored as a special string . It provides ~0.81 % error with only 12 KB of memory.

Ideal for estimating unique visitors, active users, or distinct items.

Geospatial (GEO)

Implemented on top of a sorted set, using geohash to encode latitude/longitude as scores. Commands such as GEOADD , GEOPOS , and GEORADIUS enable location‑based queries.

Typical uses include nearby search, distance calculations, and location‑based services.

Bitmap

A special string interpreted as a bit array, allowing SETBIT , GETBIT , and bitwise operations. Supports up to 2³²‑1 bits.

Used for activity tracking, Bloom filters, and bit‑wise indexing.

Bitfield

Extends the bitmap concept by allowing arbitrary‑width signed or unsigned integers to be stored and atomically manipulated within a string.

Useful for compactly storing multiple counters or attributes, e.g., gender (8 bits), age (8 bits), height (16 bits), weight (16 bits).

Example of setting and getting fields:

BITFIELD user:1:info SET u8 #0 1 SET u8 #1 25 SET u16 #2 165 SET u16 #3 50000

Overall, the article explains how Redis automatically switches between encodings based on element count and size, and provides concrete CLI examples for each data type.

PerformancecacheDatabaseRedisencodingData Structures
Top Architect
Written by

Top Architect

Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.