Skip to content

Commit

Permalink
Add redisClustervCommandToNode and redisClustervAppendCommandToNode t…
Browse files Browse the repository at this point in the history
…o API (#231)
  • Loading branch information
unikmhz authored Aug 5, 2024
1 parent 83f326b commit ebee436
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 13 deletions.
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

0 comments on commit ebee436

Please sign in to comment.