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

Function RM_StreamIteratorStart

app/redis-6.2.6/src/module.c:3472–3509  ·  view source on GitHub ↗

Sets up a stream iterator. * * - `key`: The stream key opened for reading using RedisModule_OpenKey(). * - `flags`: * - `REDISMODULE_STREAM_ITERATOR_EXCLUSIVE`: Don't include `start` and `end` * in the iterated range. * - `REDISMODULE_STREAM_ITERATOR_REVERSE`: Iterate in reverse order, starting * from the `end` of the range. * - `start`: The lower bound of the range. Use NULL f

Source from the content-addressed store, hash-verified

3470 * RedisModule_StreamIteratorStop(key);
3471 */
3472int RM_StreamIteratorStart(RedisModuleKey *key, int flags, RedisModuleStreamID *start, RedisModuleStreamID *end) {
3473 /* check args */
3474 if (!key ||
3475 (flags & ~(REDISMODULE_STREAM_ITERATOR_EXCLUSIVE |
3476 REDISMODULE_STREAM_ITERATOR_REVERSE))) {
3477 errno = EINVAL; /* key missing or invalid flags */
3478 return REDISMODULE_ERR;
3479 } else if (!key->value || key->value->type != OBJ_STREAM) {
3480 errno = ENOTSUP;
3481 return REDISMODULE_ERR; /* not a stream */
3482 } else if (key->iter) {
3483 errno = EBADF; /* iterator already started */
3484 return REDISMODULE_ERR;
3485 }
3486
3487 /* define range for streamIteratorStart() */
3488 streamID lower, upper;
3489 if (start) lower = (streamID){start->ms, start->seq};
3490 if (end) upper = (streamID){end->ms, end->seq};
3491 if (flags & REDISMODULE_STREAM_ITERATOR_EXCLUSIVE) {
3492 if ((start && streamIncrID(&lower) != C_OK) ||
3493 (end && streamDecrID(&upper) != C_OK)) {
3494 errno = EDOM; /* end is 0-0 or start is MAX-MAX? */
3495 return REDISMODULE_ERR;
3496 }
3497 }
3498
3499 /* create iterator */
3500 stream *s = key->value->ptr;
3501 int rev = flags & REDISMODULE_STREAM_ITERATOR_REVERSE;
3502 streamIterator *si = zmalloc(sizeof(*si));
3503 streamIteratorStart(si, s, start ? &lower : NULL, end ? &upper : NULL, rev);
3504 key->iter = si;
3505 key->u.stream.currentid.ms = 0; /* for RM_StreamIteratorDelete() */
3506 key->u.stream.currentid.seq = 0;
3507 key->u.stream.numfieldsleft = 0; /* for RM_StreamIteratorNextField() */
3508 return REDISMODULE_OK;
3509}
3510
3511/* Stops a stream iterator created using RedisModule_StreamIteratorStart() and
3512 * reclaims its memory.

Callers

nothing calls this directly

Calls 4

streamIncrIDFunction · 0.85
streamDecrIDFunction · 0.85
zmallocFunction · 0.85
streamIteratorStartFunction · 0.85

Tested by

no test coverage detected