Back to Redis

LLEN

content/commands/llen.md

latest1.4 KB
Original Source

Returns the length of the list stored at key. If key does not exist, it is interpreted as an empty list and 0 is returned. An error is returned when the value stored at key is not a list.

Examples

{{< clients-example set="cmds_list" step="llen" description="Foundational: Get the length of a list using LLEN (returns 0 if key doesn't exist, useful for checking list size)" difficulty="beginner" >}} redis> LPUSH mylist "World" (integer) 1 redis> LPUSH mylist "Hello" (integer) 2 redis> LLEN mylist (integer) 2 {{< /clients-example >}}

Give these commands a try in the interactive console:

{{% redis-cli %}} LPUSH mylist "World" LPUSH mylist "Hello" LLEN mylist {{% /redis-cli %}}

Redis Software and Redis Cloud compatibility

| Redis Software | Redis Cloud | <span style="min-width: 9em; display: table-cell">Notes</span> | |:----------------------|:-----------------|:------| | <span title="Supported">✅ Standard</span> <span title="Supported"><nobr>✅ Active-Active</nobr></span> | <span title="Supported">✅ Standard</span> <span title="Supported"><nobr>✅ Active-Active</nobr></span> | |

Return information

{{< multitabs id="llen-return-info" tab1="RESP2" tab2="RESP3" >}}

Integer reply: the length of the list.

-tab-sep-

Integer reply: the length of the list.

{{< /multitabs >}}