Challenge - 5 Problems
Redis EXISTS Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate1:00remaining
Check if a single key exists
Given the Redis database contains keys: user:1, user:2, and session:1, what is the output of the command
EXISTS user:1?Redis
EXISTS user:1Attempts:
2 left
💡 Hint
EXISTS returns 1 if the key exists, otherwise 0.
✗ Incorrect
The EXISTS command returns 1 if the key is present in the database. Since user:1 exists, the output is 1.
❓ query_result
intermediate1:30remaining
Check multiple keys existence count
What does the command
EXISTS user:1 user:3 session:1 return if only user:1 and session:1 exist in the Redis database?Redis
EXISTS user:1 user:3 session:1
Attempts:
2 left
💡 Hint
EXISTS returns the number of keys that exist among the given keys.
✗ Incorrect
Only user:1 and session:1 exist, so EXISTS returns 2.
📝 Syntax
advanced1:30remaining
Identify the syntax error in EXISTS command
Which option shows an invalid syntax for the EXISTS command in Redis?
Attempts:
2 left
💡 Hint
EXISTS command does not use parentheses around keys.
✗ Incorrect
Parentheses are not valid syntax in Redis commands. Option B uses parentheses, causing a syntax error.
❓ optimization
advanced2:00remaining
Optimizing key existence checks
You want to check if any of the keys user:1, user:2, user:3 exist. Which command is the most efficient to get the count of existing keys?
Attempts:
2 left
💡 Hint
EXISTS can take multiple keys at once and returns the count of existing keys.
✗ Incorrect
Using EXISTS with multiple keys in one command is efficient and returns the count directly. Option D sends multiple commands, which is less efficient.
🧠 Conceptual
expert2:00remaining
Behavior of EXISTS with expired keys
If a key named session:temp has expired and been deleted by Redis, what will
EXISTS session:temp return?Redis
EXISTS session:temp
Attempts:
2 left
💡 Hint
Expired keys are automatically removed and do not exist anymore.
✗ Incorrect
Once a key expires, it is deleted and no longer exists. EXISTS returns 0 for such keys.