0
0
Redisquery~10 mins

XADD for adding entries in Redis - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - XADD for adding entries
Start XADD command
Check stream exists?
NoCreate new stream
Yes
Generate entry ID
Add entry with fields
Return entry ID
End
This flow shows how Redis XADD adds an entry: it checks the stream, creates if missing, generates an ID, adds the entry, then returns the ID.
Execution Sample
Redis
XADD mystream * sensor-id 1234 temperature 19.8
XADD mystream * sensor-id 1235 temperature 20.1
Adds two entries to 'mystream' with auto-generated IDs and fields for sensor-id and temperature.
Execution Table
StepCommandStream Exists?Entry ID GeneratedEntry AddedOutput
1XADD mystream * sensor-id 1234 temperature 19.8No (stream created)1609459200000-0Yes1609459200000-0
2XADD mystream * sensor-id 1235 temperature 20.1Yes1609459200001-0Yes1609459200001-0
3End---No more commands
💡 All entries added; no more commands to process.
Variable Tracker
VariableStartAfter 1After 2Final
mystream entriesempty[1609459200000-0: {sensor-id:1234, temperature:19.8}][1609459200000-0: {...}, 1609459200001-0: {sensor-id:1235, temperature:20.1}]2 entries
Key Moments - 3 Insights
Why does XADD create the stream if it doesn't exist?
XADD automatically creates the stream to simplify adding entries, so you don't need to create it manually first. See execution_table step 1 where the stream was created.
What does the '*' mean in the XADD command?
The '*' tells Redis to auto-generate a unique entry ID based on the current time. This is shown in execution_table where IDs like '1609459200000-0' are generated.
Can the entry ID be specified manually instead of '*'?
Yes, you can specify your own ID, but using '*' is easier and ensures uniqueness. This example uses '*', as shown in the execution_sample.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the entry ID generated for the first XADD command?
A*
B1609459200001-0
C1609459200000-0
Dmystream
💡 Hint
Check the 'Entry ID Generated' column in row 1 of the execution_table.
At which step does the stream get created?
AStep 2
BStep 1
CStep 3
DIt is never created
💡 Hint
Look at the 'Stream Exists?' column in the execution_table for step 1.
If you replace '*' with a manual ID, how would the execution_table change?
AEntry ID Generated would show the manual ID instead of auto-generated
BStream would not be created
CEntry would not be added
DOutput would be empty
💡 Hint
Consider the 'Entry ID Generated' column and how IDs are assigned.
Concept Snapshot
XADD key * field value [field value ...]
- Adds an entry to a Redis stream
- '*' auto-generates a unique ID
- Creates stream if missing
- Returns the entry ID
- Fields are key-value pairs for the entry
Full Transcript
The XADD command in Redis adds entries to a stream. If the stream does not exist, XADD creates it automatically. The '*' symbol tells Redis to generate a unique entry ID based on the current time. Each entry consists of fields as key-value pairs. After adding, XADD returns the entry ID. This process is shown step-by-step in the execution table, tracking stream creation, ID generation, and entry addition.