Bird
Raised Fist0
Redisquery~20 mins

Why streams handle event logs in Redis - Challenge Your Understanding

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Stream Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why are Redis Streams suitable for event logs?

Which of the following best explains why Redis Streams are a good choice for handling event logs?

ABecause Redis Streams automatically delete old events without any configuration.
BBecause Redis Streams store data in a relational table format for easy querying.
CBecause Redis Streams store events in an ordered, append-only log that supports efficient reading and trimming.
DBecause Redis Streams require manual indexing of each event to maintain order.
Attempts:
2 left
💡 Hint

Think about how event logs need to keep events in order and allow new events to be added efficiently.

❓ query_result
intermediate
2:00remaining
Output of adding events to a Redis Stream

What is the output of the following Redis command sequence?

XADD mystream * event "login" user "alice"
XADD mystream * event "logout" user "bob"
XRANGE mystream - +
A[["1-0", {"event": "login", "user": "alice"}], ["2-0", {"event": "logout", "user": "bob"}]]
BSyntaxError: XRANGE requires a stream key
C[["1609459200000-0", {"event": "login", "user": "alice"}], ["1609459200001-0", {"event": "logout", "user": "bob"}]]
D[]
Attempts:
2 left
💡 Hint

Redis assigns incremental IDs starting from 1-0 if you use * for the ID.

📝 Syntax
advanced
2:00remaining
Identify the syntax error in Redis Stream command

Which option contains a syntax error when adding an event to a Redis Stream?

XADD mystream * event login user alice
AXADD mystream * event:login user:alice
BXADD mystream * event "login" user "alice"
CXADD mystream * event='login' user='alice'
DXADD mystream * event login user alice
Attempts:
2 left
💡 Hint

Check how field-value pairs should be formatted in XADD.

❓ optimization
advanced
2:00remaining
Best practice to limit Redis Stream size for event logs

Which Redis command option is best to limit the size of a stream to avoid unbounded growth when handling event logs?

AXADD mystream MINLEN 1000 * event "click" user "john"
BXADD mystream MAXLEN ~ 1000 * event "click" user "john"
CXADD mystream MAXLEN 1000 * event "click" user "john"
DXADD mystream TRIMLEN 1000 * event "click" user "john"
Attempts:
2 left
💡 Hint

Consider approximate trimming to improve performance.

🔧 Debug
expert
2:00remaining
Why does this Redis Stream consumer fail to read new events?

A consumer uses XREAD with the ID '0' to read new events from a stream but never receives any new data. Why?

XREAD BLOCK 0 STREAMS mystream 0
ABecause ID '0' reads from the beginning and blocks until new events after '0' arrive, but no new events are added.
BBecause the BLOCK 0 option causes an immediate timeout, so no data is returned.
CBecause the stream key 'mystream' does not exist, so XREAD fails silently.
DBecause the ID '0' is invalid and causes a syntax error.
Attempts:
2 left
💡 Hint

Think about how XREAD uses IDs to read new events and how blocking works.

Practice

(1/5)
1. Why are Redis streams well-suited for handling event logs?
easy
A. Because they only store one event at a time
B. Because they delete old events automatically
C. Because they store events in order with unique IDs
D. Because they require complex setup to use

Solution

  1. Step 1: Understand Redis streams storage

    Redis streams store events sequentially with unique IDs, preserving order.
  2. Step 2: Match this to event log needs

    Event logs need ordered, unique entries to track actions accurately.
  3. Final Answer:

    Because they store events in order with unique IDs -> Option C
  4. Quick Check:

    Streams = Ordered unique events [OK]
Hint: Streams keep events ordered with unique IDs [OK]
Common Mistakes:
  • Thinking streams delete old events automatically
  • Believing streams store only one event
  • Assuming streams need complex setup
2. Which Redis command is used to add a new event to a stream?
easy
A. XREAD
B. XADD
C. XRANGE
D. XDEL

Solution

  1. Step 1: Identify command to add events

    XADD is the Redis command designed to add new entries to a stream.
  2. Step 2: Differentiate from other commands

    XREAD reads events, XRANGE queries a range, XDEL deletes entries.
  3. Final Answer:

    XADD -> Option B
  4. Quick Check:

    XADD = Add event [OK]
Hint: XADD adds events to streams [OK]
Common Mistakes:
  • Confusing XADD with XREAD or XRANGE
  • Thinking XDEL adds events
  • Using XRANGE to add events
3. Given the Redis stream commands below, what will XRANGE mystream - + return?

XADD mystream * event "login" user "alice"
XADD mystream * event "logout" user "bob"
medium
A. All events in 'mystream' from the oldest to newest
B. Only the first event added to 'mystream'
C. An error because XRANGE needs a count parameter
D. No events because the stream is empty

Solution

  1. Step 1: Understand XRANGE command

    XRANGE with '-' and '+' returns all entries from oldest to newest in the stream.
  2. Step 2: Check stream content after XADD commands

    Two events were added: a login by alice and a logout by bob.
  3. Final Answer:

    All events in 'mystream' from the oldest to newest -> Option A
  4. Quick Check:

    XRANGE - + = all events [OK]
Hint: XRANGE - + returns all stream events [OK]
Common Mistakes:
  • Thinking XRANGE returns only one event
  • Believing XRANGE requires a count parameter
  • Assuming stream is empty after XADD
4. You run the command XADD mystream * event but get an error. What is the likely cause?
medium
A. XRANGE command is required before XADD
B. Using * instead of a specific ID
C. Stream 'mystream' does not exist
D. Missing field-value pairs after the event name

Solution

  1. Step 1: Check XADD syntax requirements

    XADD requires field-value pairs after the ID; 'event' lacks a value.
  2. Step 2: Validate other options

    Using '*' is correct for auto ID, streams can be created automatically, and XRANGE is unrelated.
  3. Final Answer:

    Missing field-value pairs after the event name -> Option D
  4. Quick Check:

    XADD needs field-value pairs [OK]
Hint: XADD needs pairs: field and value [OK]
Common Mistakes:
  • Thinking * is invalid for ID
  • Assuming stream must exist before XADD
  • Believing XRANGE must run first
5. You want to track user actions in a Redis stream but only keep the last 100 events to save memory. Which command option helps achieve this?
hard
A. XADD mystream MAXLEN ~ 100 * event "login" user "alice"
B. XADD mystream * event "login" user "alice" COUNT 100
C. XADD mystream * event "login" user "alice" MAXLEN 100
D. XADD mystream * event "login" user "alice" LIMIT 100

Solution

  1. Step 1: Understand MAXLEN option in XADD

    MAXLEN limits stream length; '~' makes it approximate for better performance.
  2. Step 2: Identify correct syntax for trimming

    XADD mystream MAXLEN ~ 100 * event "login" user "alice" uses 'MAXLEN ~ 100' which trims stream to about 100 entries efficiently.
  3. Final Answer:

    XADD mystream MAXLEN ~ 100 * event "login" user "alice" -> Option A
  4. Quick Check:

    MAXLEN ~ 100 trims stream length [OK]
Hint: Use MAXLEN ~ 100 to trim stream length efficiently [OK]
Common Mistakes:
  • Using MAXLEN without ~ causes slower trimming
  • Using COUNT or LIMIT which are invalid here
  • Not trimming stream and causing memory issues
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard