Some details:
xread streams numbers 1-0
returns the last 2 messages.Just note the ID field. This indicates the starting point of the consumer group’s stream in the main stream.
You can provide the special $
id to indicate you want the consumer group to start at the next new message added to the main stream.
A consumer group receives everything in the main stream. XREADGROUP is reading messages (or making the messages DELIVERED) from a consumer group’s sub-stream (which is just a duplicate of the main stream).
Deliver(from Redis stream to a specific consumer) -> Consume(by consumer) -> ACKnowledge(by consumer) Note: When a message is delivered but has not been ACKed, it’s stored in the consumer’s Pending Entries List(PEL). It’s removed from the PEL when it’s ACKed.
Things to be careful:
One of the guarantees of consumer groups is that a given consumer can only see the history of messages that were delivered to it, so a message has just a single owner. Except when XCLAIM
ed.
The ID to specify in the STREAMS option when using XREADGROUP can be one of the following two:
>
ID, which means that the consumer want to receive only messages that were never delivered to any other consumer. It just means, give me new messages.Messages need to be ACKed to be removed from the consumer’s PEL. If you choose the NOACK
option in XREADGROUP
, the message is instantly deleted on read.
When a consumer fails, other consumers can take on its pending messages to prevent message loss.
Redis streams is implemented using Radix Tree, which is similar to a trie. Because the message IDs often have common prefix, this data structure can save space and search time. Moreover, subsequent field names are compressed. Because message fields are often the same, this can save space as well.