LLEN command in redis

LLEN key

This command returns the length of the list stored at the specified key. If the key does not exist zero is returned (the same behavior as for empty lists). If the value stored at the key is not a list an error is returned.

TIME COMPLEXITY: O(1)

RETURN VALUE: Integer reply of the length of the list.

Syntax:

LLEN KEY_NAME

Example 1: When the key is present and contains some elements.

redis:6379> LPUSH myList 100
(integer) 1
redis:6379> LPUSH myList 200
(integer) 2
redis:6379> LPUSH myList 300
(integer) 3
redis:6379> LLEN myList
(integer) 3

Output

3


Example 2: When the key is not present.

redis:6379> LLEN myList2
(integer) 0

Output

0

No comments:

Post a Comment