LLEN:获取列表的长度

用户可以通过执行 LLEN 命令来获取列表的长度,即列表包含的元素数量:

LLEN list

比如对于图 4-16 所示的几个列表来说,对它们执行 LLEN 命令将获得以下结果:

redis> LLEN todo
(integer) 3
redis> LLEN alphabets
(integer) 8
redis> LLEN msg-queue
(integer) 4
image 2025 01 03 16 05 32 700
Figure 1. 图4-16 几个不同长度的列表

对于不存在的列表,LLEN 命令将返回 0 作为结果:

redis> LLEN not-exists-list
(integer) 0

其他信息

  • 复杂度:O(1)。

  • 版本要求:LLEN 命令从 Redis 1.0.0 版本开始可用。