Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add redisClustervCommandToNode and redisClustervAppendCommandToNode to library API #231

Merged
merged 2 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 35 additions & 13 deletions hircluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -3045,10 +3045,10 @@ void *redisClusterCommand(redisClusterContext *cc, const char *format, ...) {
return reply;
}

void *redisClusterCommandToNode(redisClusterContext *cc, redisClusterNode *node,
const char *format, ...) {
void *redisClustervCommandToNode(redisClusterContext *cc,
redisClusterNode *node, const char *format,
va_list ap) {
redisContext *c;
va_list ap;
int ret;
void *reply;
int updating_slotmap = 0;
Expand All @@ -3066,9 +3066,7 @@ void *redisClusterCommandToNode(redisClusterContext *cc, redisClusterNode *node,
memset(cc->errstr, '\0', sizeof(cc->errstr));
}

va_start(ap, format);
ret = redisvAppendCommand(c, format, ap);
va_end(ap);

if (ret != REDIS_OK) {
__redisClusterSetError(cc, c->err, c->errstr);
Expand Down Expand Up @@ -3101,6 +3099,18 @@ void *redisClusterCommandToNode(redisClusterContext *cc, redisClusterNode *node,
return reply;
}

void *redisClusterCommandToNode(redisClusterContext *cc, redisClusterNode *node,
const char *format, ...) {
va_list ap;
redisReply *reply = NULL;

va_start(ap, format);
reply = redisClustervCommandToNode(cc, node, format, ap);
va_end(ap);

return reply;
}

void *redisClusterCommandArgv(redisClusterContext *cc, int argc,
const char **argv, const size_t *argvlen) {
redisReply *reply = NULL;
Expand Down Expand Up @@ -3237,7 +3247,6 @@ int redisClustervAppendCommand(redisClusterContext *cc, const char *format,

int redisClusterAppendCommand(redisClusterContext *cc, const char *format,
...) {

int ret;
va_list ap;

Expand All @@ -3252,11 +3261,10 @@ int redisClusterAppendCommand(redisClusterContext *cc, const char *format,
return ret;
}

int redisClusterAppendCommandToNode(redisClusterContext *cc,
redisClusterNode *node, const char *format,
...) {
int redisClustervAppendCommandToNode(redisClusterContext *cc,
redisClusterNode *node, const char *format,
va_list ap) {
redisContext *c;
va_list ap;
struct cmd *command = NULL;
char *cmd = NULL;
int len;
Expand All @@ -3277,10 +3285,7 @@ int redisClusterAppendCommandToNode(redisClusterContext *cc,
return REDIS_ERR;
}

/* Allocate cmd and encode the variadic command */
va_start(ap, format);
len = redisvFormatCommand(&cmd, format, ap);
va_end(ap);

if (len == -1) {
goto oom;
Expand Down Expand Up @@ -3319,6 +3324,23 @@ int redisClusterAppendCommandToNode(redisClusterContext *cc,
return REDIS_ERR;
}

int redisClusterAppendCommandToNode(redisClusterContext *cc,
redisClusterNode *node, const char *format,
...) {
int ret;
va_list ap;

if (cc == NULL || node == NULL || format == NULL) {
return REDIS_ERR;
}

va_start(ap, format);
ret = redisClustervAppendCommandToNode(cc, node, format, ap);
va_end(ap);

return ret;
}

int redisClusterAppendCommandArgv(redisClusterContext *cc, int argc,
const char **argv, const size_t *argvlen) {
int ret;
Expand Down
6 changes: 6 additions & 0 deletions hircluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ void *redisClusterCommandToNode(redisClusterContext *cc, redisClusterNode *node,
/* Variadic using va_list */
void *redisClustervCommand(redisClusterContext *cc, const char *format,
va_list ap);
void *redisClustervCommandToNode(redisClusterContext *cc,
redisClusterNode *node, const char *format,
va_list ap);
/* Using argc and argv */
void *redisClusterCommandArgv(redisClusterContext *cc, int argc,
const char **argv, const size_t *argvlen);
Expand All @@ -265,6 +268,9 @@ int redisClusterAppendCommandToNode(redisClusterContext *cc,
/* Variadic using va_list */
int redisClustervAppendCommand(redisClusterContext *cc, const char *format,
va_list ap);
int redisClustervAppendCommandToNode(redisClusterContext *cc,
redisClusterNode *node, const char *format,
va_list ap);
/* Using argc and argv */
int redisClusterAppendCommandArgv(redisClusterContext *cc, int argc,
const char **argv, const size_t *argvlen);
Expand Down
Loading