Challenge - 5 Problems
HLEN Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate1:30remaining
What is the output of HLEN on a hash with three fields?
Consider a Redis hash stored with key
user:1000 having fields name, age, and email. What will the command HLEN user:1000 return?Redis
HMSET user:1000 name "Alice" age "30" email "alice@example.com" HLEN user:1000
Attempts:
2 left
💡 Hint
HLEN returns the number of fields in the hash stored at the key.
✗ Incorrect
HLEN returns the count of fields in the hash. Since there are three fields, the output is 3.
❓ query_result
intermediate1:00remaining
What does HLEN return for a non-existing key?
If you run
HLEN on a key that does not exist in Redis, what is the output?Redis
HLEN non_existing_key
Attempts:
2 left
💡 Hint
Redis treats non-existing hashes as empty.
✗ Incorrect
HLEN returns 0 for keys that do not exist because it treats them as empty hashes.
📝 Syntax
advanced1:00remaining
Which HLEN command syntax is correct?
Identify the correct syntax to get the number of fields in a Redis hash named
session:123.Attempts:
2 left
💡 Hint
Redis commands do not use parentheses or braces.
✗ Incorrect
The correct syntax is just the command followed by the key name without quotes or parentheses.
🧠 Conceptual
advanced1:30remaining
What happens if HLEN is run on a key holding a string?
If a Redis key
mykey holds a string value, what will happen when you run HLEN mykey?Redis
SET mykey "hello"
HLEN mykeyAttempts:
2 left
💡 Hint
HLEN only works on hashes, not strings.
✗ Incorrect
HLEN on a key holding a string returns a WRONGTYPE error because the command expects a hash.
❓ optimization
expert2:00remaining
Efficiently counting fields in a large hash
You have a very large Redis hash with millions of fields. You want to get the number of fields quickly. Which approach is best?
Attempts:
2 left
💡 Hint
HLEN is optimized for counting fields in a hash.
✗ Incorrect
HLEN is a fast command that returns the number of fields without transferring all data. Other methods are slower or require extra work.