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

Function streamIteratorStart

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

Initialize the stream iterator, so that we can call iterating functions * to get the next items. This requires a corresponding streamIteratorStop() * at the end. The 'rev' parameter controls the direction. If it's zero the * iteration is from the start to the end element (inclusive), otherwise * if rev is non-zero, the iteration is reversed. * * Once the iterator is initialized, we iterate l

Source from the content-addressed store, hash-verified

1045 * }
1046 * streamIteratorStop(&myiterator); */
1047void streamIteratorStart(streamIterator *si, stream *s, streamID *start, streamID *end, int rev) {
1048 /* Initialize the iterator and translates the iteration start/stop
1049 * elements into a 128 big big-endian number. */
1050 if (start) {
1051 streamEncodeID(si->start_key,start);
1052 } else {
1053 si->start_key[0] = 0;
1054 si->start_key[1] = 0;
1055 }
1056
1057 if (end) {
1058 streamEncodeID(si->end_key,end);
1059 } else {
1060 si->end_key[0] = UINT64_MAX;
1061 si->end_key[1] = UINT64_MAX;
1062 }
1063
1064 /* Seek the correct node in the radix tree. */
1065 raxStart(&si->ri,s->rax);
1066 if (!rev) {
1067 if (start && (start->ms || start->seq)) {
1068 raxSeek(&si->ri,"<=",(unsigned char*)si->start_key,
1069 sizeof(si->start_key));
1070 if (raxEOF(&si->ri)) raxSeek(&si->ri,"^",NULL,0);
1071 } else {
1072 raxSeek(&si->ri,"^",NULL,0);
1073 }
1074 } else {
1075 if (end && (end->ms || end->seq)) {
1076 raxSeek(&si->ri,"<=",(unsigned char*)si->end_key,
1077 sizeof(si->end_key));
1078 if (raxEOF(&si->ri)) raxSeek(&si->ri,"$",NULL,0);
1079 } else {
1080 raxSeek(&si->ri,"$",NULL,0);
1081 }
1082 }
1083 si->stream = s;
1084 si->lp = NULL; /* There is no current listpack right now. */
1085 si->lp_ele = NULL; /* Current listpack cursor. */
1086 si->rev = rev; /* Direction, if non-zero reversed, from end to start. */
1087}
1088
1089/* Return 1 and store the current item ID at 'id' if there are still
1090 * elements within the iteration range, otherwise return 0 in order to

Callers 8

rewriteStreamObjectFunction · 0.85
xorObjectDigestFunction · 0.85
RM_StreamIteratorStartFunction · 0.85
streamDeleteItemFunction · 0.85
streamLastValidIDFunction · 0.85
streamReplyWithRangeFunction · 0.85
xclaimCommandFunction · 0.85

Calls 4

streamEncodeIDFunction · 0.85
raxStartFunction · 0.85
raxSeekFunction · 0.85
raxEOFFunction · 0.85

Tested by

no test coverage detected