LLEN

LLEN key
Available since:
Redis Open Source 1.0.0
Time complexity:
O(1)
ACL categories:
@read, @list, @fast,
Compatibility:
Redis Software and Redis Cloud compatibility

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.

Required arguments

key

The name of the key that holds the list.

Examples

Foundational: Get the length of a list using LLEN (returns 0 if key doesn't exist, useful for checking list size)
redis> LPUSH mylist "World"
(integer) 1
redis> LPUSH mylist "Hello"
(integer) 2
redis> LLEN mylist
(integer) 2
res11 = r.lpush("mylist", "World")
print(res11) # >>> 1

res12 = r.lpush("mylist", "Hello")
print(res12) # >>> 2

res13 = r.llen("mylist")
print(res13)  # >>> 2

const res11 = await client.lPush('mylist', 'World');
console.log(res11); // 1

const res12 = await client.lPush('mylist', 'Hello');
console.log(res12); // 2

const res13 = await client.lLen('mylist');
console.log(res13); // 2

        long lLenResult1 = jedis.lpush("mylist", "World");
        System.out.println(lLenResult1); // >>> 1

        long lLenResult2 = jedis.lpush("mylist", "Hello");
        System.out.println(lLenResult2); // >>> 2

        long lLenResult3 = jedis.llen("mylist");
        System.out.println(lLenResult3); // >>> 2
            CompletableFuture<Void> llen = asyncCommands.lpush("mylist", "World").thenCompose(res11 -> {
                System.out.println(res11); // >>> 1

                return asyncCommands.lpush("mylist", "Hello");
            }).thenCompose(res12 -> {
                System.out.println(res12); // >>> 2

                return asyncCommands.llen("mylist");
            })
                    .thenAccept(res13 -> System.out.println(res13)) // >>> 2
                    .toCompletableFuture();
            Mono<Void> llen = reactiveCommands.lpush("mylist", "World").doOnNext(res11 -> {
                System.out.println(res11); // >>> 1
            }).flatMap(res11 -> reactiveCommands.lpush("mylist", "Hello")).doOnNext(res12 -> {
                System.out.println(res12); // >>> 2
            }).flatMap(res12 -> reactiveCommands.llen("mylist")).doOnNext(res13 -> {
                System.out.println(res13); // >>> 2
            }).then();
	lPushResult1, err := rdb.LPush(ctx, "mylist", "World").Result()

	if err != nil {
		panic(err)
	}

	fmt.Println(lPushResult1) // >>> 1

	lPushResult2, err := rdb.LPush(ctx, "mylist", "Hello").Result()

	if err != nil {
		panic(err)
	}

	fmt.Println(lPushResult2) // >>> 2

	lLenResult, err := rdb.LLen(ctx, "mylist").Result()

	if err != nil {
		panic(err)
	}

	fmt.Println(lLenResult) // >>> 2
        long lLenResult1 = db.ListLeftPush("mylist", "World");
        Console.WriteLine(lLenResult1); // >>> 1

        long lLenResult2 = db.ListLeftPush("mylist", "Hello");
        Console.WriteLine(lLenResult2); // >>> 2

        long lLenResult3 = db.ListLength("mylist");
        Console.WriteLine(lLenResult3); // >>> 2
        $res11 = $r->lpush('mylist', 'World');
        echo $res11 . PHP_EOL;
        // >>> 1

        $res12 = $r->lpush('mylist', 'Hello');
        echo $res12 . PHP_EOL;
        // >>> 2

        $res13 = $r->llen('mylist');
        echo $res13 . PHP_EOL;
        // >>> 2

Give these commands a try in the interactive console:

LPUSH mylist "World" LPUSH mylist "Hello" LLEN mylist

Redis Software and Redis Cloud compatibility

Redis
Software
Redis
Cloud
Notes
✅ Standard
✅ Active-Active
✅ Standard
✅ Active-Active

Return information

Integer reply: the length of the list.
RATE THIS PAGE
Back to top ↑