Open-Source Wikis

/

Redis

/

Features

/

Data types

redis/redis

Data types

Active contributors: antirez, Oran Agra, Itamar Haber, debing.sun, Binbin.

Redis exposes about a dozen built-in data types, each backed by one or more storage encodings that the server selects adaptively based on size and content.

Type → file mapping

Type Source Encodings
String src/t_string.c INT (small integer), EMBSTR (≤44 bytes), RAW (SDS).
List src/t_list.c LISTPACK (small), QUICKLIST (large).
Set src/t_set.c INTSET (all integers, small), LISTPACK (small mixed), HT (hash table).
Hash src/t_hash.c LISTPACK (small, no field TTLs), LISTPACK_EX/LISTPACK_HFE (small, with TTLs), HT (large).
Sorted set src/t_zset.c LISTPACK (small), SKIPLIST (large; skiplist + dict combo).
Stream src/t_stream.c A radix tree of listpacks (STREAM).
Bitmap src/bitops.c Treated as a string with bit-level commands.
Bitfield src/bitops.c Same backing as bitmap; bit-level integer access.
Hyperloglog src/hyperloglog.c A custom encoding inside a string (HLL_DENSE / HLL_SPARSE).
Geospatial src/geo.c, src/geohash.c, src/geohash_helper.c A sorted set with geohash scores.
Vector set modules/vector-sets/ An HNSW graph + per-key metadata. Built into the server when atomics are available.
GCRA rate limiter src/gcra.c A custom string encoding for token-bucket state.

Each t_*.c file is structured the same way: encoding constants, conversion helpers, command implementations, RDB save/load callbacks, and (for some types) AOF rewriters.

Strings

Strings are byte arrays. The encoding depends on content:

  • INT — the value is a 64-bit signed integer. The integer is stored directly in robj.ptr, no separate buffer.
  • EMBSTR — ≤44 bytes. The robj and SDS data are co-allocated in a single zmalloc block to save an allocation.
  • RAW — SDS. The robj and SDS are separate allocations.

Commands: GET, SET, MSET, MGET, INCR, INCRBY, INCRBYFLOAT, APPEND, STRLEN, GETRANGE, SETRANGE, SETEX, PSETEX, SETNX, GETSET, GETDEL, GETEX, LCS, COPY, …

Lists

A list is an ordered sequence of strings. Two encodings:

  • LISTPACK — for short lists with small elements (default ≤128 entries, ≤64 bytes each).
  • QUICKLIST — a doubly-linked list of listpacks. Each node has a packed listpack; the list as a whole supports head/tail O(1) plus efficient iteration.

The conversion thresholds are list-max-listpack-size and list-compress-depth. With list-compress-depth N, the middle nodes (excluding the first and last N) are LZF-compressed.

Commands: LPUSH, RPUSH, LPOP, RPOP, LMOVE, LRANGE, LINDEX, LSET, LINSERT, LLEN, LREM, LTRIM, LPOS, BLPOP, BRPOP, LMPOP, BLMPOP, …

Sets

An unordered collection of unique strings. Three encodings:

  • INTSET — when every member is a small integer, sorted in a packed array. O(log N) membership via binary search.
  • LISTPACK — for small mixed-type sets.
  • HT — a dict with NULL values.

Conversion when size exceeds set-max-intset-entries / set-max-listpack-entries / element size exceeds set-max-listpack-value.

Commands: SADD, SREM, SISMEMBER, SMISMEMBER, SRANDMEMBER, SPOP, SUNION, SINTER, SDIFF, SINTERCARD, SCARD, SMOVE, SMEMBERS, SSCAN, …

Hashes

A field → value map. Three encodings:

  • LISTPACK — small hashes without field TTLs.
  • LISTPACK_EX / LISTPACK_HFE — small hashes with per-field TTLs (Redis 7.4+).
  • HT — a dict.

Commands: HSET, HGET, HMSET, HMGET, HDEL, HEXISTS, HLEN, HSTRLEN, HKEYS, HVALS, HGETALL, HRANDFIELD, HINCRBY, HINCRBYFLOAT, HSCAN, plus the field-TTL family: HEXPIRE, HPEXPIRE, HEXPIREAT, HPEXPIREAT, HTTL, HPTTL, HEXPIRETIME, HPEXPIRETIME, HPERSIST, HSETEX, HGETEX, HGETDEL.

The TTL-aware encodings stash a 4-byte expiration delta after each field's value in the listpack, plus a per-key minimum-expiration index in keymeta to make active expiration cheap.

Sorted sets

Members with scores. Two encodings:

  • LISTPACK — small zsets.
  • SKIPLIST — a skiplist for ordered access plus a dict for O(1) score lookup.

Commands: ZADD, ZREM, ZSCORE, ZINCRBY, ZRANGE, ZRANGEBYSCORE, ZRANGEBYLEX, ZRANGESTORE, ZREVRANGE, ZRANK, ZREVRANK, ZCOUNT, ZCARD, ZPOPMIN, ZPOPMAX, BZPOPMIN, BZPOPMAX, ZUNIONSTORE, ZINTERSTORE, ZDIFFSTORE, ZRANDMEMBER, ZSCAN, ZMPOP, BZMPOP, …

Streams

An append-only log with random access. The encoding (STREAM) is a rax of listpacks: each listpack holds a contiguous run of entries; the rax indexes by entry id. Consumer groups, pending entries lists, and last-delivered ids are stored in side structures attached to the stream.

Commands: XADD, XREAD, XREADGROUP, XLEN, XRANGE, XREVRANGE, XDEL, XTRIM, XGROUP CREATE/SETID/DESTROY/CREATECONSUMER/DELCONSUMER, XACK, XPENDING, XCLAIM, XAUTOCLAIM, XINFO STREAM/GROUPS/CONSUMERS, plus the new XDELEX, XACKDEL, XNACK, XIDMPRECORD.

Bitmaps and bitfields

Operations on a string at the bit level. SETBIT, GETBIT, BITCOUNT, BITOP, BITPOS, BITFIELD, BITFIELD_RO. The implementation in src/bitops.c treats the string buffer as a sequence of bits (or, for BITFIELD, of arbitrary-width signed/unsigned integers).

HyperLogLog

A probabilistic counter for cardinality estimation. Encoded inside a string with a custom header + register array. PFADD, PFCOUNT, PFMERGE, PFDEBUG, PFSELFTEST. Implementation: src/hyperloglog.c.

Geospatial

A geo set is a sorted set whose members are tagged with (longitude, latitude) and whose scores are 52-bit interleaved geohashes. GEOADD, GEODIST, GEOPOS, GEOHASH, GEOSEARCH, GEOSEARCHSTORE, GEORADIUS (deprecated), GEORADIUSBYMEMBER (deprecated). Implementation: src/geo.c + src/geohash.c + src/geohash_helper.c.

Vector sets

A new top-level type (Redis 8). Members are vectors; queries find approximate nearest neighbours using HNSW. The implementation is in modules/vector-sets/ (hnsw.c, vset.c, vset_config.c) and is built directly into redis-server when the compiler supports C11 atomics.

Commands: VADD, VSIM, VREM, VCARD, VINFO, VDIM, VEMB, VLINKS, VGETATTR, VSETATTR, VRANDMEMBER, VISMEMBER, VMISMEMBER. The wire spec is in src/commands/v*.json.

Probabilistic types (modules)

When BUILD_WITH_MODULES=yes, the server loads redisbloom (Bloom, Cuckoo, Count-Min Sketch, t-digest, Top-K) as a module. These types are defined in upstream redisbloom (modules/redisbloom/ is a stub that fetches it). They register via the Module API.

Encoding selection thresholds

Config Default Effect
hash-max-listpack-entries 128 Convert hash to HT past this.
hash-max-listpack-value 64 Convert hash to HT if any value exceeds this size.
list-max-listpack-size -2 (8 KiB) Negative values mean per-listpack size cap.
list-compress-depth 0 Compress middle listpacks if non-zero.
set-max-listpack-entries 128 Convert set to HT.
set-max-intset-entries 512 Convert intset to listpack/HT.
zset-max-listpack-entries 128 Convert zset to skiplist.
zset-max-listpack-value 64 Convert zset if any element exceeds this size.
stream-node-max-bytes 4096 Listpack-node size cap inside a stream's rax.
stream-node-max-entries 100 Listpack-node entry cap.

OBJECT ENCODING <key> reports the current encoding; DEBUG STRINGMATCH-LEN and MEMORY USAGE <key> give other diagnostics.

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

Data types – Redis wiki | Factory