0
0
Redisquery~30 mins

XADD for adding entries in Redis - Mini Project: Build & Apply

Choose your learning style9 modes available
Using XADD to Add Entries to a Redis Stream
📖 Scenario: You are building a simple event logging system using Redis streams. Each event will be stored as an entry in a Redis stream called event_stream. This will help you keep track of user actions in a web application.
🎯 Goal: Learn how to add entries to a Redis stream using the XADD command. You will create a stream key, set a maximum length for the stream, and add event entries with specific fields.
📋 What You'll Learn
Create a Redis stream key named event_stream.
Set a maximum length of 100 entries for the stream.
Add entries with fields user and action.
Use the XADD command with the MAXLEN option.
Add at least two entries to the stream.
💡 Why This Matters
🌍 Real World
Redis streams are used in real-time event logging, messaging systems, and data pipelines to store ordered data efficiently.
💼 Career
Knowing how to add and manage entries in Redis streams is valuable for backend developers, DevOps engineers, and anyone working with real-time data processing.
Progress0 / 4 steps
1
Create the Redis stream key event_stream
Use the XADD command to create a Redis stream key called event_stream and add the first entry with fields user set to alice and action set to login. Use * for the entry ID to let Redis generate it automatically.
Redis
Need a hint?

Use XADD event_stream * user alice action login to add the first entry.

2
Add a configuration to limit the stream length
Modify the XADD command to add a maximum length of 100 entries to the event_stream using the MAXLEN option with approximate trimming (~). Add a second entry with user set to bob and action set to logout.
Redis
Need a hint?

Use XADD event_stream MAXLEN ~ 100 * user bob action logout to add the second entry with length limit.

3
Add a third entry with the same length limit
Add a third entry to the event_stream using XADD with the same maximum length of 100 entries. Set the user field to carol and the action field to purchase.
Redis
Need a hint?

Use XADD event_stream MAXLEN ~ 100 * user carol action purchase to add the third entry.

4
Complete the stream setup with all entries
Ensure the Redis stream event_stream has three entries added with the XADD command, each using the MAXLEN ~ 100 option for the second and third entries. The entries must have the exact fields and values: first entry with user alice action login, second with user bob action logout, and third with user carol action purchase.
Redis
Need a hint?

Check that all three XADD commands are present with correct fields and options.