Redis Data Types

Strings, hashes, sets, sorted sets.

Overview

Redis ships several data types beyond strings, and picking the right one for each workload turns Redis from a key-value cache into a precision tool. Hashes serialise objects without copying full strings; sets answer membership questions in O(1); sorted sets handle leaderboards natively. Defaulting to strings for everything wastes memory and forces application-level work that Redis could do faster in C.

The approach

Three habits make Redis usage idiomatic: pick types per workload rather than per habit, use hashes for objects to save memory, and document the rationale so future engineers do not regress to strings.

Why this compounds

Each correct type choice compounds across every access. Memory footprint shrinks; latency drops; the team’s caching mental model deepens. New services pick the right type from day one rather than defaulting to strings and migrating later.