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

Function RM_ReplyWithArray

src/module.cpp:1579–1596  ·  view source on GitHub ↗

Reply with an array type of 'len' elements. However 'len' other calls * to `ReplyWith*` style functions must follow in order to emit the elements * of the array. * * When producing arrays with a number of element that is not known beforehand * the function can be called with the special count * REDISMODULE_POSTPONED_ARRAY_LEN, and the actual number of elements can be * later set with RedisM

Source from the content-addressed store, hash-verified

1577 *
1578 * The function always returns REDISMODULE_OK. */
1579int RM_ReplyWithArray(RedisModuleCtx *ctx, long len) {
1580 client *c = moduleGetReplyClient(ctx);
1581 AeLocker locker;
1582
1583 if (c == NULL) return REDISMODULE_OK;
1584 std::unique_lock<fastlock> lock(c->lock);
1585 locker.arm(c);
1586 if (len == REDISMODULE_POSTPONED_ARRAY_LEN) {
1587 ctx->postponed_arrays = (void**)zrealloc(ctx->postponed_arrays,sizeof(void*)*
1588 (ctx->postponed_arrays_count+1), MALLOC_LOCAL);
1589 ctx->postponed_arrays[ctx->postponed_arrays_count] =
1590 addReplyDeferredLen(c);
1591 ctx->postponed_arrays_count++;
1592 } else {
1593 addReplyArrayLen(c,len);
1594 }
1595 return REDISMODULE_OK;
1596}
1597
1598/* Reply to the client with a null array, simply null in RESP3
1599 * null array in RESP2.

Callers

nothing calls this directly

Calls 5

moduleGetReplyClientFunction · 0.85
zreallocFunction · 0.85
addReplyDeferredLenFunction · 0.85
addReplyArrayLenFunction · 0.85
armMethod · 0.80

Tested by

no test coverage detected