# 《Redis 设计与实现》笔记 - 压缩列表

## 数据结构

```
+-------+------+-----+------+------+---+------+-----+
|zlbytes|zltail|zllen|entry1|entry2|...|entryN|zlend|
+-------+------+-----+------+------+---+------+-----+
```

压缩列表是 Redis 为了节约内存而开发的，由一系列特殊编码的连续内存块组成的顺序型数据结构。

压缩列表中的字段描述：

1. zlbytes 记录压缩列表占用的内存字节数；
2. zltail 记录压缩列表尾节点的偏移量；
3. zllen 记录压缩列表的节点数量
4. entryX 是压缩列表保存的节点数据；
5. 每个 entry 压缩列表节点可以保存一个字节数组或者一个整数值
6. 字节数组支持以下三种长度：63（2^6-1）、16,383（2^14-1）、4,294,967,295（2^32-1）
7. 整数值支持以下六种长度：4 bit、1 byte、3 byte、int16\_t、int32\_t、int64\_t
8. zlend 是一个特殊值，值为 `0xFF`，用于记录压缩列表的末端。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gitbook.fantasticmao.cn/tech/shu-ju-ku/redis/redis-she-ji-yu-shi-xian-bi-ji-ya-suo-lie-biao.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
