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

Function RM_ReplySetArrayLength

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

When RedisModule_ReplyWithArray() is used with the argument * REDISMODULE_POSTPONED_ARRAY_LEN, because we don't know beforehand the number * of items we are going to output as elements of the array, this function * will take care to set the array length. * * Since it is possible to have multiple array replies pending with unknown * length, this function guarantees to always set the latest ar

Source from the content-addressed store, hash-verified

1609 * that is not easy to calculate in advance the number of elements.
1610 */
1611void RM_ReplySetArrayLength(RedisModuleCtx *ctx, long len) {
1612 client *c = moduleGetReplyClient(ctx);
1613 if (c == NULL) return;
1614 if (ctx->postponed_arrays_count == 0) {
1615 serverLog(LL_WARNING,
1616 "API misuse detected in module %s: "
1617 "RedisModule_ReplySetArrayLength() called without previous "
1618 "RedisModule_ReplyWithArray(ctx,REDISMODULE_POSTPONED_ARRAY_LEN) "
1619 "call.", ctx->module->name);
1620 return;
1621 }
1622 ctx->postponed_arrays_count--;
1623 setDeferredArrayLen(c,
1624 ctx->postponed_arrays[ctx->postponed_arrays_count],
1625 len);
1626 if (ctx->postponed_arrays_count == 0) {
1627 zfree(ctx->postponed_arrays);
1628 ctx->postponed_arrays = NULL;
1629 }
1630}
1631
1632/* Reply with a bulk string, taking in input a C buffer pointer and length.
1633 *

Callers

nothing calls this directly

Calls 3

moduleGetReplyClientFunction · 0.85
setDeferredArrayLenFunction · 0.85
zfreeFunction · 0.70

Tested by

no test coverage detected