0
0
Redisquery~5 mins

Stream entry IDs in Redis

Choose your learning style9 modes available
Introduction
Stream entry IDs help you identify and order messages in a Redis stream easily.
When you want to add messages to a stream and keep track of their order.
When you need to read messages from a stream starting from a specific point.
When you want to acknowledge processing of messages using their IDs.
When you want to trim or manage stream length based on entry IDs.
When you want to query or filter stream entries by their IDs.
Syntax
Redis
stream_entry_id := <millisecondsTime>-<sequenceNumber>
Example: 1526985058136-0
The ID has two parts separated by a dash: the time in milliseconds and a sequence number.
If multiple entries are added in the same millisecond, the sequence number increases to keep IDs unique.
Examples
An entry ID with timestamp 1526985058136 milliseconds and sequence number 0.
Redis
1526985058136-0
Another entry added in the same millisecond but with sequence number 1.
Redis
1526985058136-1
Use * to let Redis auto-generate the next stream entry ID.
Redis
*
Sample Program
Add two entries to 'mystream' with auto-generated IDs, then list all entries.
Redis
XADD mystream * name Alice
XADD mystream * name Bob
XRANGE mystream - +
OutputSuccess
Important Notes
Stream entry IDs are always unique and sorted by time.
You can specify your own ID but it must be greater than the last ID in the stream.
Using '*' lets Redis handle ID generation automatically.
Summary
Stream entry IDs uniquely identify each message in a Redis stream.
They consist of a timestamp and a sequence number separated by a dash.
You can use '*' to auto-generate IDs when adding entries.