Databases 8 min read

Redis Ziplist (Compressed List): Principles, Memory Layout, and Applications

This article explains the internal structure and encoding of Redis's ziplist (compressed list), describes its memory layout and node format, and analyzes how Redis leverages this data structure across different types such as lists, hashes, and sorted sets to reduce memory usage and fragmentation.

Architecture Digest
Architecture Digest
Architecture Digest
Redis Ziplist (Compressed List): Principles, Memory Layout, and Applications

Redis is a popular in‑memory key‑value database that supports several data structures; among its internal optimizations is the ziplist, also called a compressed list, which stores a series of elements together with encoding information in a contiguous memory region.

The ziplist memory block consists of five parts: zlbytes (total byte size), zltail (offset to the tail entry), zllen (number of entries), the variable‑length entry area ( entryX ), and a fixed end byte zlend (value 255).

Each entry is composed of three fields: previous length , encoding , and content . The previous length stores the size of the preceding entry and can be 1 or 5 bytes, enabling backward traversal. The encoding field indicates the type (string or integer) and length of the content , using 1, 2, or 5 bytes.

The content holds the actual data; its type and length are determined by the encoding. Depending on conditions, the content may be an integer or a byte array, and in some cases its length can be zero.

Redis applies ziplist encoding to several data structures when certain thresholds are met (e.g., small number of elements or short element size). The article lists the data types that use ziplist, including lists, hashes, sorted sets, and even GEO indexes.

Analysis shows that ziplist reduces memory consumption by packing many small items into a single contiguous block, which also lessens memory fragmentation—a benefit the author calls "merged storage." However, operations on ziplist have O(N) complexity, so Redis enables it only when the performance impact is acceptable.

In summary, the ziplist is a memory‑efficient encoding technique used by Redis to store small collections, balancing lower memory usage against higher operation cost, and its design offers useful insights for developers dealing with in‑memory data structures.

Memory OptimizationRedisdata-structuresdatabasesziplistCompressed List
Architecture Digest
Written by

Architecture Digest

Focusing on Java backend development, covering application architecture from top-tier internet companies (high availability, high performance, high stability), big data, machine learning, Java architecture, and other popular fields.

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.