mirror of
http://github.com/valkey-io/valkey
synced 2024-11-22 09:17:20 +00:00
0399b5a27e
Adding a test for coverage for RM_Call in a new "misc" unit to be used for various short simple tests also solves compilation warnings in redismodule.h and fork.c
56 lines
1.7 KiB
C
56 lines
1.7 KiB
C
#define REDISMODULE_EXPERIMENTAL_API
|
|
#include "redismodule.h"
|
|
|
|
#include <string.h>
|
|
#include <assert.h>
|
|
#include <unistd.h>
|
|
#include <errno.h>
|
|
|
|
int test_call_generic(RedisModuleCtx *ctx, RedisModuleString **argv, int argc)
|
|
{
|
|
if (argc<2) {
|
|
RedisModule_WrongArity(ctx);
|
|
return REDISMODULE_OK;
|
|
}
|
|
|
|
const char* cmdname = RedisModule_StringPtrLen(argv[1], NULL);
|
|
RedisModuleCallReply *reply = RedisModule_Call(ctx, cmdname, "v", argv+2, argc-2);
|
|
if (reply) {
|
|
RedisModule_ReplyWithCallReply(ctx, reply);
|
|
RedisModule_FreeCallReply(reply);
|
|
} else {
|
|
RedisModule_ReplyWithError(ctx, strerror(errno));
|
|
}
|
|
return REDISMODULE_OK;
|
|
}
|
|
|
|
int test_call_info(RedisModuleCtx *ctx, RedisModuleString **argv, int argc)
|
|
{
|
|
RedisModuleCallReply *reply;
|
|
if (argc>1)
|
|
reply = RedisModule_Call(ctx, "info", "s", argv[1]);
|
|
else
|
|
reply = RedisModule_Call(ctx, "info", "");
|
|
if (reply) {
|
|
RedisModule_ReplyWithCallReply(ctx, reply);
|
|
RedisModule_FreeCallReply(reply);
|
|
} else {
|
|
RedisModule_ReplyWithError(ctx, strerror(errno));
|
|
}
|
|
return REDISMODULE_OK;
|
|
}
|
|
|
|
int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
|
|
REDISMODULE_NOT_USED(argv);
|
|
REDISMODULE_NOT_USED(argc);
|
|
if (RedisModule_Init(ctx,"misc",1,REDISMODULE_APIVER_1)== REDISMODULE_ERR)
|
|
return REDISMODULE_ERR;
|
|
|
|
if (RedisModule_CreateCommand(ctx,"test.call_generic", test_call_generic,"",0,0,0) == REDISMODULE_ERR)
|
|
return REDISMODULE_ERR;
|
|
if (RedisModule_CreateCommand(ctx,"test.call_info", test_call_info,"",0,0,0) == REDISMODULE_ERR)
|
|
return REDISMODULE_ERR;
|
|
|
|
return REDISMODULE_OK;
|
|
}
|