What will be the output of the command XREAD COUNT 2 STREAMS mystream 1609459200000-0?
medium
A. [["mystream", [["1609459201000-0", {"name": "Bob"}], ["1609459202000-0", {"name": "Carol"}]]]]
B. [["mystream", [["1609459200000-0", {"name": "Alice"}], ["1609459201000-0", {"name": "Bob"}]]]]
C. [["mystream", [["1609459202000-0", {"name": "Carol"}]]]]
D. Error: Invalid COUNT usage
Solution
Step 1: Understand COUNT and starting ID
Starting at 1609459200000-0 means reading from the first entry. COUNT 2 limits to 2 entries.
Step 2: Select the first two entries
The first two entries are Alice and Bob with IDs 1609459200000-0 and 1609459201000-0.
Final Answer:
[["mystream", [["1609459200000-0", {"name": "Alice"}], ["1609459201000-0", {"name": "Bob"}]]]] -> Option B
Quick Check:
COUNT limits entries read = A [OK]
Hint: COUNT limits number of entries returned [OK]
Common Mistakes:
Starting from next ID instead of given ID
Ignoring COUNT and returning all entries
Misunderstanding the output format
4. You run the command XREAD STREAMS mystream 0-0 COUNT 2 but get an error. Which of the following is the most likely cause?
medium
A. The COUNT argument is placed after the STREAMS keyword
B. The stream name is missing
C. The ID format is incorrect
D. XREAD does not support COUNT option
Solution
Step 1: Recall XREAD syntax
Modifiers like COUNT must precede the STREAMS keyword: XREAD [COUNT count] STREAMS key id ...
Step 2: Analyze the given command
COUNT 2 is placed after STREAMS mystream 0-0, which is invalid and causes a syntax error.
Step 3: Rule out other options
Stream name present, ID 0-0 valid, COUNT supported.
Final Answer:
The COUNT argument is placed after the STREAMS keyword -> Option A
Quick Check:
COUNT after STREAMS = error A [OK]
Hint: COUNT and BLOCK must precede STREAMS [OK]
Common Mistakes:
Placing COUNT after STREAMS keyword
Omitting stream name
Assuming COUNT is unsupported
5. You want to read new entries from two streams, streamA and streamB, starting from IDs 0-0 and 1609459200000-0 respectively, and wait up to 5000 milliseconds if no new entries arrive. Which command correctly achieves this?