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
| 1649 | * that is not easy to calculate in advance the number of elements. |
| 1650 | */ |
| 1651 | void 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 | * |
nothing calls this directly
no test coverage detected