MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / RM_ReplySetArrayLength

Function RM_ReplySetArrayLength

src/module.cpp:1651–1673  ·  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

1649 * that is not easy to calculate in advance the number of elements.
1650 */
1651void RM_ReplySetArrayLength(RedisModuleCtx *ctx, long len) {
1652 client *c = moduleGetReplyClient(ctx);
1653 if (c == NULL) return;
1654 AeLocker locker;
1655 std::unique_lock<fastlock> lock(c->lock);
1656 locker.arm(c);
1657 if (ctx->postponed_arrays_count == 0) {
1658 serverLog(LL_WARNING,
1659 "API misuse detected in module %s: "
1660 "RedisModule_ReplySetArrayLength() called without previous "
1661 "RedisModule_ReplyWithArray(ctx,REDISMODULE_POSTPONED_ARRAY_LEN) "
1662 "call.", ctx->module->name);
1663 return;
1664 }
1665 ctx->postponed_arrays_count--;
1666 setDeferredArrayLen(c,
1667 ctx->postponed_arrays[ctx->postponed_arrays_count],
1668 len);
1669 if (ctx->postponed_arrays_count == 0) {
1670 zfree(ctx->postponed_arrays);
1671 ctx->postponed_arrays = NULL;
1672 }
1673}
1674
1675/* Reply with a bulk string, taking in input a C buffer pointer and length.
1676 *

Callers

nothing calls this directly

Calls 5

moduleGetReplyClientFunction · 0.85
serverLogFunction · 0.85
setDeferredArrayLenFunction · 0.85
zfreeFunction · 0.85
armMethod · 0.80

Tested by

no test coverage detected