diff --git a/src/module.c b/src/module.c index ef358d3a8..636202a9f 100644 --- a/src/module.c +++ b/src/module.c @@ -2126,15 +2126,23 @@ int RM_ReplyWithEmptyString(RedisModuleCtx *ctx) { return REDISMODULE_OK; } +/* Reply with a binary safe string, which should not be escaped or filtered + * taking in input a C buffer pointer, length and a 3 character type/extension. + * + * The function always returns REDISMODULE_OK. */ +int RM_ReplyWithVerbatimStringType(RedisModuleCtx *ctx, const char *buf, size_t len, const char *ext) { + client *c = moduleGetReplyClient(ctx); + if (c == NULL) return REDISMODULE_OK; + addReplyVerbatim(c, buf, len, ext); + return REDISMODULE_OK; +} + /* Reply with a binary safe string, which should not be escaped or filtered * taking in input a C buffer pointer and length. * * The function always returns REDISMODULE_OK. */ int RM_ReplyWithVerbatimString(RedisModuleCtx *ctx, const char *buf, size_t len) { - client *c = moduleGetReplyClient(ctx); - if (c == NULL) return REDISMODULE_OK; - addReplyVerbatim(c, buf, len, "txt"); - return REDISMODULE_OK; + return RM_ReplyWithVerbatimStringType(ctx, buf, len, "txt"); } /* Reply to the client with a NULL. @@ -10242,6 +10250,7 @@ void moduleRegisterCoreAPI(void) { REGISTER_API(ReplyWithString); REGISTER_API(ReplyWithEmptyString); REGISTER_API(ReplyWithVerbatimString); + REGISTER_API(ReplyWithVerbatimStringType); REGISTER_API(ReplyWithStringBuffer); REGISTER_API(ReplyWithCString); REGISTER_API(ReplyWithNull); diff --git a/src/redismodule.h b/src/redismodule.h index 586b0c6ee..dae02531b 100644 --- a/src/redismodule.h +++ b/src/redismodule.h @@ -663,6 +663,7 @@ REDISMODULE_API int (*RedisModule_ReplyWithCString)(RedisModuleCtx *ctx, const c REDISMODULE_API int (*RedisModule_ReplyWithString)(RedisModuleCtx *ctx, RedisModuleString *str) REDISMODULE_ATTR; REDISMODULE_API int (*RedisModule_ReplyWithEmptyString)(RedisModuleCtx *ctx) REDISMODULE_ATTR; REDISMODULE_API int (*RedisModule_ReplyWithVerbatimString)(RedisModuleCtx *ctx, const char *buf, size_t len) REDISMODULE_ATTR; +REDISMODULE_API int (*RedisModule_ReplyWithVerbatimStringType)(RedisModuleCtx *ctx, const char *buf, size_t len, const char *ext) REDISMODULE_ATTR; REDISMODULE_API int (*RedisModule_ReplyWithNull)(RedisModuleCtx *ctx) REDISMODULE_ATTR; REDISMODULE_API int (*RedisModule_ReplyWithBool)(RedisModuleCtx *ctx, int b) REDISMODULE_ATTR; REDISMODULE_API int (*RedisModule_ReplyWithDouble)(RedisModuleCtx *ctx, double d) REDISMODULE_ATTR; @@ -946,6 +947,7 @@ static int RedisModule_Init(RedisModuleCtx *ctx, const char *name, int ver, int REDISMODULE_GET_API(ReplyWithString); REDISMODULE_GET_API(ReplyWithEmptyString); REDISMODULE_GET_API(ReplyWithVerbatimString); + REDISMODULE_GET_API(ReplyWithVerbatimStringType); REDISMODULE_GET_API(ReplyWithNull); REDISMODULE_GET_API(ReplyWithBool); REDISMODULE_GET_API(ReplyWithCallReply);