Challenge - 5 Problems
Redis List Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate1:30remaining
What is the output of LLEN on a non-empty list?
Given a Redis list stored with key
fruits containing ["apple", "banana", "cherry"], what will the command LLEN fruits return?Redis
LPUSH fruits apple LPUSH fruits banana LPUSH fruits cherry LLEN fruits
Attempts:
2 left
💡 Hint
LLEN returns the number of items in the list stored at the given key.
✗ Incorrect
The list
fruits has three items after the LPUSH commands, so LLEN returns 3.❓ query_result
intermediate1:00remaining
What does LLEN return for a missing key?
If you run
LLEN vegetables on a Redis key vegetables that does not exist, what is the output?Redis
LLEN vegetables
Attempts:
2 left
💡 Hint
LLEN returns zero if the key does not exist.
✗ Incorrect
In Redis, LLEN returns 0 for keys that do not exist, treating them as empty lists.
📝 Syntax
advanced1:00remaining
Which LLEN command syntax is correct?
Which of the following Redis commands correctly returns the length of the list stored at key
mylist?Attempts:
2 left
💡 Hint
Redis commands do not use parentheses or colons in this context.
✗ Incorrect
The correct syntax is
LLEN key. Options B, C, and D are invalid syntax.❓ optimization
advanced1:30remaining
Efficiently checking if a Redis list is empty
You want to check if the Redis list
tasks is empty without retrieving all elements. Which command is the most efficient way to do this?Attempts:
2 left
💡 Hint
Think about which command returns the list length without transferring all data.
✗ Incorrect
LLEN returns the length of the list efficiently. LRANGE returns all elements, which is costly. LPOP removes an element, changing the list. EXISTS only checks if the key exists, not if the list is empty.
🧠 Conceptual
expert1:30remaining
Understanding LLEN behavior with different data types
What happens if you run
LLEN on a Redis key user:1 that stores a string value instead of a list?Redis
SET user:1 "John" LLEN user:1
Attempts:
2 left
💡 Hint
LLEN only works on list data types.
✗ Incorrect
If the key stores a string, LLEN returns a Redis error about wrong data type because it expects a list.