diff options
author | guybe7 <guy.benoish@redislabs.com> | 2022-04-17 14:43:22 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-17 15:43:22 +0300 |
commit | f49ff156ecd62aee104cff9f88fb62948575e6b0 (patch) | |
tree | d7c5b09264550a2c5f17177b59182788318b24ec /tests/modules | |
parent | 789c94feceb7cb0b618dcb912c0151625d913887 (diff) | |
download | redis-f49ff156ecd62aee104cff9f88fb62948575e6b0.tar.gz |
Add RM_PublishMessageShard (#10543)
since PUBLISH and SPUBLISH use different dictionaries for channels and clients,
and we already have an API for PUBLISH, it only makes sense to have one for SPUBLISH
Add test coverage and unifying some test infrastructure.
Diffstat (limited to 'tests/modules')
-rw-r--r-- | tests/modules/Makefile | 3 | ||||
-rw-r--r-- | tests/modules/publish.c | 42 |
2 files changed, 44 insertions, 1 deletions
diff --git a/tests/modules/Makefile b/tests/modules/Makefile index 16b5570aa..ac4c3e27b 100644 --- a/tests/modules/Makefile +++ b/tests/modules/Makefile @@ -57,7 +57,8 @@ TEST_MODULES = \ cmdintrospection.so \ eventloop.so \ moduleconfigs.so \ - moduleconfigstwo.so + moduleconfigstwo.so \ + publish.so .PHONY: all diff --git a/tests/modules/publish.c b/tests/modules/publish.c new file mode 100644 index 000000000..eee96d689 --- /dev/null +++ b/tests/modules/publish.c @@ -0,0 +1,42 @@ +#include "redismodule.h" +#include <string.h> +#include <assert.h> +#include <unistd.h> + +#define UNUSED(V) ((void) V) + +int cmd_publish_classic(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) +{ + if (argc != 3) + return RedisModule_WrongArity(ctx); + + int receivers = RedisModule_PublishMessage(ctx, argv[1], argv[2]); + RedisModule_ReplyWithLongLong(ctx, receivers); + return REDISMODULE_OK; +} + +int cmd_publish_shard(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) +{ + if (argc != 3) + return RedisModule_WrongArity(ctx); + + int receivers = RedisModule_PublishMessageShard(ctx, argv[1], argv[2]); + RedisModule_ReplyWithLongLong(ctx, receivers); + return REDISMODULE_OK; +} + +int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { + UNUSED(argv); + UNUSED(argc); + + if (RedisModule_Init(ctx,"publish",1,REDISMODULE_APIVER_1)== REDISMODULE_ERR) + return REDISMODULE_ERR; + + if (RedisModule_CreateCommand(ctx,"publish.classic",cmd_publish_classic,"",0,0,0) == REDISMODULE_ERR) + return REDISMODULE_ERR; + + if (RedisModule_CreateCommand(ctx,"publish.shard",cmd_publish_shard,"",0,0,0) == REDISMODULE_ERR) + return REDISMODULE_ERR; + + return REDISMODULE_OK; +} |