0
0
Redisquery~5 mins

Why streams handle event logs in Redis

Choose your learning style9 modes available
Introduction

Streams help keep a list of events in order. They make it easy to track what happened and when.

You want to record user actions like clicks or logins in order.
You need to keep a history of changes to data for auditing.
You want to process events one by one as they happen.
You want to share event data between different parts of your app.
You want to replay past events to fix or analyze problems.
Syntax
Redis
XADD key ID field value [field value ...]
XADD adds a new event to the stream with fields and values.
ID can be * to auto-generate a unique timestamp-based ID.
Examples
Adds an event to 'mystream' with user and action details. The ID is auto-generated.
Redis
XADD mystream * user alice action login
Adds an event with a specific ID and sensor data fields.
Redis
XADD mystream 1526985058136-0 temperature 22 humidity 60
Sample Program

This adds a signup event to the 'eventlog' stream and then reads all events from start to end.

Redis
XADD eventlog * event "user_signup" user_id "1234"
XRANGE eventlog - +
OutputSuccess
Important Notes

Streams keep events in the order they arrive, which is great for logs.

You can read streams in small parts to process events step-by-step.

Using streams helps build reliable systems that track what happened over time.

Summary

Streams store events in order with unique IDs.

They are perfect for logging and tracking actions.

Redis commands like XADD and XRANGE help add and read events easily.