diff options
author | Binbin <binloveplay1314@qq.com> | 2023-04-12 15:11:29 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-12 10:11:29 +0300 |
commit | bfec2d700b8b0ccf6669e0408b5c5c75299ef47e (patch) | |
tree | 04e20c7adfdb2738f59f50f9fcc5c3f43e272556 /tests/modules/reply.c | |
parent | 997fa41e99271cc5c3a79e9bf8a1332b3d9ab0c2 (diff) | |
download | redis-bfec2d700b8b0ccf6669e0408b5c5c75299ef47e.tar.gz |
Add RM_ReplyWithErrorFormat that can support format (#11923)
* Add RM_ReplyWithErrorFormat that can support format
Reply with the error create from a printf format and arguments.
If the error code is already passed in the string 'fmt', the error
code provided is used, otherwise the string "-ERR " for the generic
error code is automatically added.
The usage is, for example:
RedisModule_ReplyWithErrorFormat(ctx, "An error: %s", "foo");
RedisModule_ReplyWithErrorFormat(ctx, "-WRONGTYPE Wrong Type: %s", "foo");
The function always returns REDISMODULE_OK.
Diffstat (limited to 'tests/modules/reply.c')
-rw-r--r-- | tests/modules/reply.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/tests/modules/reply.c b/tests/modules/reply.c index f890560e0..c5baa6635 100644 --- a/tests/modules/reply.c +++ b/tests/modules/reply.c @@ -156,6 +156,14 @@ int rw_error(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { return RedisModule_ReplyWithError(ctx, "An error"); } +int rw_error_format(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { + if (argc != 3) return RedisModule_WrongArity(ctx); + + return RedisModule_ReplyWithErrorFormat(ctx, + RedisModule_StringPtrLen(argv[1], NULL), + RedisModule_StringPtrLen(argv[2], NULL)); +} + int rw_verbatim(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { if (argc != 2) return RedisModule_WrongArity(ctx); @@ -197,6 +205,8 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) return REDISMODULE_ERR; if (RedisModule_CreateCommand(ctx,"rw.error",rw_error,"",0,0,0) != REDISMODULE_OK) return REDISMODULE_ERR; + if (RedisModule_CreateCommand(ctx,"rw.error_format",rw_error_format,"",0,0,0) != REDISMODULE_OK) + return REDISMODULE_ERR; if (RedisModule_CreateCommand(ctx,"rw.verbatim",rw_verbatim,"",0,0,0) != REDISMODULE_OK) return REDISMODULE_ERR; |