Challenge - 5 Problems
Time-based Event Queue Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Retrieve events scheduled before a specific timestamp
Given a Redis sorted set named
events where the score is the event timestamp, which command returns all events scheduled before timestamp 1650000000?Attempts:
2 left
💡 Hint
Remember that scores in sorted sets represent timestamps and you want all events with scores less than or equal to 1650000000.
✗ Incorrect
ZRANGEBYSCORE with -inf to 1650000000 returns all members with scores up to that timestamp. Option A returns events after that timestamp. Option A reverses the order but with wrong bounds. Option A uses index range, not score range.
📝 Syntax
intermediate1:30remaining
Identify the correct syntax to add a timed event
Which Redis command correctly adds an event named
event42 scheduled at timestamp 1680000000 to a sorted set events?Attempts:
2 left
💡 Hint
ZADD syntax requires the score first, then the member.
✗ Incorrect
Option A uses correct syntax: ZADD key score member. Option A swaps score and member causing error. Option A uses parentheses incorrectly. Option A misses the score argument.
❓ optimization
advanced2:00remaining
Efficiently removing expired events
You want to remove all events from the
events sorted set that have timestamps less than the current time 1690000000. Which command is the most efficient to do this?Attempts:
2 left
💡 Hint
Removing by score range is best for timestamp-based removals.
✗ Incorrect
ZREMRANGEBYSCORE removes all members with scores in the given range efficiently. Option B tries to remove a member named '1690000000' which likely doesn't exist. Option B is invalid syntax. Option B removes by rank, which is unrelated to timestamps.
🔧 Debug
advanced2:00remaining
Why does this time-based event retrieval return no results?
A developer runs this command to get events before timestamp 1700000000:
ZRANGEBYSCORE events (1700000000 -inf. Why does it return no results?Attempts:
2 left
💡 Hint
Check the order of min and max arguments in ZRANGEBYSCORE.
✗ Incorrect
ZRANGEBYSCORE requires the min score first, then max score. Here max is given first, so no results are returned. Parentheses exclude the boundary but do not cause empty results if order is correct. Negative infinity is supported.
🧠 Conceptual
expert2:30remaining
Choosing the best data structure for time-based event queues
Which Redis data structure is best suited for implementing a time-based event queue where events must be processed in order of their scheduled timestamps?
Attempts:
2 left
💡 Hint
Consider which structure supports ordering by timestamp and efficient range queries.
✗ Incorrect
Sorted Sets store members with scores, allowing ordering by timestamp and efficient retrieval of events in time order. Lists maintain insertion order but do not support score-based queries. Hashes and Sets do not maintain order by score.