Challenge - 5 Problems
Unique Visitor Tracking Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate1:30remaining
Counting unique visitors using Redis sets
Given the following Redis commands executed in order:
1. SADD visitors 101 102 103
2. SADD visitors 102 104
3. SADD visitors 105
4. SCARD visitors
What is the output of the last command?
1. SADD visitors 101 102 103
2. SADD visitors 102 104
3. SADD visitors 105
4. SCARD visitors
What is the output of the last command?
Redis
SADD visitors 101 102 103 SADD visitors 102 104 SADD visitors 105 SCARD visitors
Attempts:
2 left
💡 Hint
Remember that sets only store unique elements.
✗ Incorrect
The set 'visitors' after all SADD commands contains unique IDs: 101, 102, 103, 104, 105. So the count is 5.
🧠 Conceptual
intermediate1:00remaining
Why use sets for unique visitor tracking?
Why are Redis sets a good choice for tracking unique visitors on a website?
Attempts:
2 left
💡 Hint
Think about how duplicates are handled.
✗ Incorrect
Redis sets store unique elements only, so adding the same visitor ID multiple times does not increase the count.
📝 Syntax
advanced1:30remaining
Identify the correct Redis command to add multiple visitors
Which of the following Redis commands correctly adds visitor IDs 201, 202, and 203 to the set named 'daily_visitors'?
Attempts:
2 left
💡 Hint
Check the exact Redis command name and argument format.
✗ Incorrect
The correct command is SADD followed by the set name and the list of members separated by spaces.
❓ optimization
advanced2:00remaining
Efficiently tracking unique visitors across multiple days
You have daily sets of visitors: 'visitors_day1', 'visitors_day2', and 'visitors_day3'. You want to find the total unique visitors over these three days. Which Redis command is the most efficient to get this count without creating a new set?
Attempts:
2 left
💡 Hint
Look for a command that returns the union without storing it.
✗ Incorrect
SUNION returns the union of sets without storing it. Then count the number of elements in the returned set client-side. Option A stores a new set, which is less efficient.
🔧 Debug
expert2:00remaining
Debugging incorrect unique visitor count
A developer runs these commands:
1. SADD visitors 301 302 303
2. SADD visitors 302 304
3. DEL visitors
4. SCARD visitors
The SCARD command returns 0, but the developer expected 4. What is the reason?
1. SADD visitors 301 302 303
2. SADD visitors 302 304
3. DEL visitors
4. SCARD visitors
The SCARD command returns 0, but the developer expected 4. What is the reason?
Attempts:
2 left
💡 Hint
Think about what DEL does to a key.
✗ Incorrect
DEL removes the entire key and its data. After deletion, the set does not exist, so SCARD returns 0.