MCPcopy Create free account
hub / github.com/F-Stack/f-stack / streamReplyWithRangeFromConsumerPEL

Function streamReplyWithRangeFromConsumerPEL

app/redis-6.2.6/src/t_stream.c:1618–1653  ·  view source on GitHub ↗

This is an helper function for streamReplyWithRange() when called with * group and consumer arguments, but with a range that is referring to already * delivered messages. In this case we just emit messages that are already * in the history of the consumer, fetching the IDs from its PEL. * * Note that this function does not have a 'rev' argument because it's not * possible to iterate in rever

Source from the content-addressed store, hash-verified

1616 * to the client. However clients only reach this code path when they are
1617 * fetching the history of already retrieved messages, which is rare. */
1618size_t streamReplyWithRangeFromConsumerPEL(client *c, stream *s, streamID *start, streamID *end, size_t count, streamConsumer *consumer) {
1619 raxIterator ri;
1620 unsigned char startkey[sizeof(streamID)];
1621 unsigned char endkey[sizeof(streamID)];
1622 streamEncodeID(startkey,start);
1623 if (end) streamEncodeID(endkey,end);
1624
1625 size_t arraylen = 0;
1626 void *arraylen_ptr = addReplyDeferredLen(c);
1627 raxStart(&ri,consumer->pel);
1628 raxSeek(&ri,">=",startkey,sizeof(startkey));
1629 while(raxNext(&ri) && (!count || arraylen < count)) {
1630 if (end && memcmp(ri.key,end,ri.key_len) > 0) break;
1631 streamID thisid;
1632 streamDecodeID(ri.key,&thisid);
1633 if (streamReplyWithRange(c,s,&thisid,&thisid,1,0,NULL,NULL,
1634 STREAM_RWR_RAWENTRIES,NULL) == 0)
1635 {
1636 /* Note that we may have a not acknowledged entry in the PEL
1637 * about a message that's no longer here because was removed
1638 * by the user by other means. In that case we signal it emitting
1639 * the ID but then a NULL entry for the fields. */
1640 addReplyArrayLen(c,2);
1641 addReplyStreamID(c,&thisid);
1642 addReplyNullArray(c);
1643 } else {
1644 streamNACK *nack = ri.data;
1645 nack->delivery_time = mstime();
1646 nack->delivery_count++;
1647 }
1648 arraylen++;
1649 }
1650 raxStop(&ri);
1651 setDeferredArrayLen(c,arraylen_ptr,arraylen);
1652 return arraylen;
1653}
1654
1655/* -----------------------------------------------------------------------
1656 * Stream commands implementation

Callers 1

streamReplyWithRangeFunction · 0.85

Calls 13

streamEncodeIDFunction · 0.85
addReplyDeferredLenFunction · 0.85
raxStartFunction · 0.85
raxSeekFunction · 0.85
raxNextFunction · 0.85
streamDecodeIDFunction · 0.85
streamReplyWithRangeFunction · 0.85
addReplyArrayLenFunction · 0.85
addReplyStreamIDFunction · 0.85
addReplyNullArrayFunction · 0.85
raxStopFunction · 0.85
setDeferredArrayLenFunction · 0.85

Tested by

no test coverage detected