Commit f4e0129f authored by antirez's avatar antirez
Browse files

Modules: RedisModule_ReplyWithCallReply().

parent 6054089f
...@@ -87,7 +87,7 @@ typedef struct RedisModuleCommandProxy RedisModuleCommandProxy; ...@@ -87,7 +87,7 @@ typedef struct RedisModuleCommandProxy RedisModuleCommandProxy;
/* Reply of RM_Call() function. The function is filled in a lazy /* Reply of RM_Call() function. The function is filled in a lazy
* way depending on the function called on the reply structure. By default * way depending on the function called on the reply structure. By default
* only the type and proto are filled. */ * only the type, proto and protolen are filled. */
struct RedisModuleCallReply { struct RedisModuleCallReply {
RedisModuleCtx *ctx; RedisModuleCtx *ctx;
int type; /* REDISMODULE_REPLY_... */ int type; /* REDISMODULE_REPLY_... */
...@@ -470,6 +470,13 @@ int RM_ReplyWithNull(RedisModuleCtx *ctx) { ...@@ -470,6 +470,13 @@ int RM_ReplyWithNull(RedisModuleCtx *ctx) {
return REDISMODULE_OK; return REDISMODULE_OK;
} }
/* Reply exactly what a Redis command returned us with RM_Call(). */
int RM_ReplyWithCallReply(RedisModuleCtx *ctx, RedisModuleCallReply *reply) {
sds proto = sdsnewlen(reply->proto, reply->protolen);
addReplySds(ctx->client,proto);
return REDISMODULE_OK;
}
/* -------------------------------------------------------------------------- /* --------------------------------------------------------------------------
* Commands replication API * Commands replication API
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
...@@ -1204,6 +1211,7 @@ void moduleRegisterCoreAPI(void) { ...@@ -1204,6 +1211,7 @@ void moduleRegisterCoreAPI(void) {
REGISTER_API(ReplyWithString); REGISTER_API(ReplyWithString);
REGISTER_API(ReplyWithStringBuffer); REGISTER_API(ReplyWithStringBuffer);
REGISTER_API(ReplyWithNull); REGISTER_API(ReplyWithNull);
REGISTER_API(ReplyWithCallReply);
REGISTER_API(GetSelectedDb); REGISTER_API(GetSelectedDb);
REGISTER_API(SelectDb); REGISTER_API(SelectDb);
REGISTER_API(OpenKey); REGISTER_API(OpenKey);
......
...@@ -694,3 +694,4 @@ Command implementations, on keys position request, must reply with ...@@ -694,3 +694,4 @@ Command implementations, on keys position request, must reply with
`REDISMODULE_KEYPOS_OK` to signal the request was processed, otherwise `REDISMODULE_KEYPOS_OK` to signal the request was processed, otherwise
Cluster returns an error for those module commands that are not able to Cluster returns an error for those module commands that are not able to
describe the position of keys. describe the position of keys.
...@@ -51,6 +51,21 @@ int HelloPushCall_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, in ...@@ -51,6 +51,21 @@ int HelloPushCall_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, in
return REDISMODULE_OK; return REDISMODULE_OK;
} }
/* HELLO.PUSH.CALL2
* This is exaxctly as HELLO.PUSH.CALL, but shows how we can reply to the
* client using directly a reply object that Call() returned. */
int HelloPushCall2_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc)
{
if (argc != 3) return RedisModule_WrongArity(ctx);
RedisModuleCallReply *reply;
reply = RedisModule_Call(ctx,"RPUSH","ss",argv[1],argv[2]);
RedisModule_ReplyWithCallReply(ctx,reply);
RedisModule_FreeCallReply(reply);
return REDISMODULE_OK;
}
/* HELLO.LIST.SUM.LEN returns the total length of all the items inside /* HELLO.LIST.SUM.LEN returns the total length of all the items inside
* a Redis list, by using the high level Call() API. * a Redis list, by using the high level Call() API.
* This command is an example of the array reply access. */ * This command is an example of the array reply access. */
...@@ -306,6 +321,10 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx) { ...@@ -306,6 +321,10 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx) {
HelloPushCall_RedisCommand) == REDISMODULE_ERR) HelloPushCall_RedisCommand) == REDISMODULE_ERR)
return REDISMODULE_ERR; return REDISMODULE_ERR;
if (RedisModule_CreateCommand(ctx,"hello.push.call2",
HelloPushCall2_RedisCommand) == REDISMODULE_ERR)
return REDISMODULE_ERR;
if (RedisModule_CreateCommand(ctx,"hello.list.sum.len", if (RedisModule_CreateCommand(ctx,"hello.list.sum.len",
HelloListSumLen_RedisCommand) == REDISMODULE_ERR) HelloListSumLen_RedisCommand) == REDISMODULE_ERR)
return REDISMODULE_ERR; return REDISMODULE_ERR;
......
...@@ -86,6 +86,7 @@ int REDISMODULE_API_FUNC(RedisModule_ReplyWithArray)(RedisModuleCtx *ctx, int le ...@@ -86,6 +86,7 @@ int REDISMODULE_API_FUNC(RedisModule_ReplyWithArray)(RedisModuleCtx *ctx, int le
int REDISMODULE_API_FUNC(RedisModule_ReplyWithStringBuffer)(RedisModuleCtx *ctx, const char *buf, size_t len); int REDISMODULE_API_FUNC(RedisModule_ReplyWithStringBuffer)(RedisModuleCtx *ctx, const char *buf, size_t len);
int REDISMODULE_API_FUNC(RedisModule_ReplyWithString)(RedisModuleCtx *ctx, RedisModuleString *str); int REDISMODULE_API_FUNC(RedisModule_ReplyWithString)(RedisModuleCtx *ctx, RedisModuleString *str);
int REDISMODULE_API_FUNC(RedisModule_ReplyWithNull)(RedisModuleCtx *ctx); int REDISMODULE_API_FUNC(RedisModule_ReplyWithNull)(RedisModuleCtx *ctx);
int REDISMODULE_API_FUNC(RedisModule_ReplyWithCallReply)(RedisModuleCtx *ctx, RedisModuleCallReply *reply);
int REDISMODULE_API_FUNC(RedisModule_StringToLongLong)(RedisModuleString *str, long long *ll); int REDISMODULE_API_FUNC(RedisModule_StringToLongLong)(RedisModuleString *str, long long *ll);
void REDISMODULE_API_FUNC(RedisModule_AutoMemory)(RedisModuleCtx *ctx); void REDISMODULE_API_FUNC(RedisModule_AutoMemory)(RedisModuleCtx *ctx);
int REDISMODULE_API_FUNC(RedisModule_Replicate)(RedisModuleCtx *ctx, const char *cmdname, const char *fmt, ...); int REDISMODULE_API_FUNC(RedisModule_Replicate)(RedisModuleCtx *ctx, const char *cmdname, const char *fmt, ...);
...@@ -111,6 +112,7 @@ static int RedisModule_Init(RedisModuleCtx *ctx, const char *name, int ver, int ...@@ -111,6 +112,7 @@ static int RedisModule_Init(RedisModuleCtx *ctx, const char *name, int ver, int
REDISMODULE_GET_API(ReplyWithStringBuffer); REDISMODULE_GET_API(ReplyWithStringBuffer);
REDISMODULE_GET_API(ReplyWithString); REDISMODULE_GET_API(ReplyWithString);
REDISMODULE_GET_API(ReplyWithNull); REDISMODULE_GET_API(ReplyWithNull);
REDISMODULE_GET_API(ReplyWithCallReply);
REDISMODULE_GET_API(GetSelectedDb); REDISMODULE_GET_API(GetSelectedDb);
REDISMODULE_GET_API(SelectDb); REDISMODULE_GET_API(SelectDb);
REDISMODULE_GET_API(OpenKey); REDISMODULE_GET_API(OpenKey);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment