From 6ed678a91490f62a828bc9cb76eb78e190f660b4 Mon Sep 17 00:00:00 2001 From: Yusaku Kaneta Date: Mon, 17 Oct 2016 18:22:52 +0900 Subject: [PATCH 1/2] supported optional modes --- rmutil/util.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/rmutil/util.h b/rmutil/util.h index 10930a3..9249a53 100644 --- a/rmutil/util.h +++ b/rmutil/util.h @@ -13,13 +13,15 @@ return REDISMODULE_ERR; \ } - -#define __rmutil_register_cmd(ctx, cmd, f, mode) if (RedisModule_CreateCommand(ctx, cmd, f, mode, \ - 1, 1, 1) == REDISMODULE_ERR) return REDISMODULE_ERR; +#define __rmutil_register_cmd(ctx, cmd, f, mode) \ + if (RedisModule_CreateCommand(ctx, cmd, f, \ + (!strcmp(mode, "readonly ")) ? "readonly" : \ + (!strcmp(mode, "write ")) ? "write" : mode, \ + 1, 1, 1) == REDISMODULE_ERR) return REDISMODULE_ERR; -#define RMUtil_RegisterReadCmd(ctx, cmd, f) __rmutil_register_cmd(ctx, cmd, f, "readonly") +#define RMUtil_RegisterReadCmd(ctx, cmd, f, ...) __rmutil_register_cmd(ctx, cmd, f, "readonly " __VA_ARGS__) -#define RMUtil_RegisterWriteCmd(ctx, cmd, f) __rmutil_register_cmd(ctx, cmd, f, "write") +#define RMUtil_RegisterWriteCmd(ctx, cmd, f, ...) __rmutil_register_cmd(ctx, cmd, f, "write " __VA_ARGS__) /* RedisModule utilities. */ From 95bb4dcb43a91a065517d6be4c897486bdb1f403 Mon Sep 17 00:00:00 2001 From: Yusaku Kaneta Date: Mon, 17 Oct 2016 18:22:57 +0900 Subject: [PATCH 2/2] added an optional mode to the example module --- example/module.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/module.c b/example/module.c index b990a70..8e5f294 100644 --- a/example/module.c +++ b/example/module.c @@ -137,7 +137,7 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx) { } // register example.hgetset - using the shortened utility registration macro - RMUtil_RegisterWriteCmd(ctx, "example.hgetset", HGetSetCommand); + RMUtil_RegisterWriteCmd(ctx, "example.hgetset", HGetSetCommand, "fast"); // register the unit test RMUtil_RegisterWriteCmd(ctx, "example.test", TestModule);