Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
733280d9
Commit
733280d9
authored
Sep 23, 2019
by
filipecosta90
Browse files
[fix] un-refactor the code. [perf] replyWithStatus now makes usage of addReplyProto
parent
4a30a26f
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/module.c
View file @
733280d9
...
...
@@ -1120,6 +1120,19 @@ int RM_ReplyWithLongLong(RedisModuleCtx *ctx, long long ll) {
return REDISMODULE_OK;
}
/* Reply with an error or simple string (status message). Used to implement
* ReplyWithSimpleString() and ReplyWithError().
* The function always returns REDISMODULE_OK. */
int replyWithStatus(RedisModuleCtx *ctx, const char *msg, char *prefix) {
client *c = moduleGetReplyClient(ctx);
if (c == NULL) return REDISMODULE_OK;
const size_t len = strlen(msg);
addReplyProto(c,"-",1);
addReplyProto(c,msg,len);
addReplyProto(c,"\r\n",2);
return REDISMODULE_OK;
}
/* Reply with the error 'err'.
*
* Note that 'err' must contain all the error, including
...
...
@@ -1135,13 +1148,7 @@ int RM_ReplyWithLongLong(RedisModuleCtx *ctx, long long ll) {
* The function always returns REDISMODULE_OK.
*/
int RM_ReplyWithError(RedisModuleCtx *ctx, const char *err) {
client *c = moduleGetReplyClient(ctx);
if (c == NULL) return REDISMODULE_OK;
const size_t len = strlen(err);
addReplyProto(c,"-",1);
addReplyProto(c,err,len);
addReplyProto(c,"\r\n",2);
return REDISMODULE_OK;
return replyWithStatus(ctx,err,"-");
}
/* Reply with a simple string (+... \r\n in RESP protocol). This replies
...
...
@@ -1150,13 +1157,7 @@ int RM_ReplyWithError(RedisModuleCtx *ctx, const char *err) {
*
* The function always returns REDISMODULE_OK. */
int RM_ReplyWithSimpleString(RedisModuleCtx *ctx, const char *msg) {
client *c = moduleGetReplyClient(ctx);
if (c == NULL) return REDISMODULE_OK;
const size_t len = strlen(msg);
addReplyProto(c,"+",1);
addReplyProto(c,msg,len);
addReplyProto(c,"\r\n",2);
return REDISMODULE_OK;
return replyWithStatus(ctx,msg,"+");
}
/* Reply with an array type of 'len' elements. However 'len' other calls
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment