diff --git a/include/valkey/valkeycluster.h b/include/valkey/valkeycluster.h index fe5c2c1f..61cc8535 100644 --- a/include/valkey/valkeycluster.h +++ b/include/valkey/valkeycluster.h @@ -226,6 +226,9 @@ void *valkeyClusterCommandToNode(valkeyClusterContext *cc, /* Variadic using va_list */ void *valkeyClustervCommand(valkeyClusterContext *cc, const char *format, va_list ap); +void *valkeyClustervCommandToNode(valkeyClusterContext *cc, + valkeyClusterNode *node, const char *format, + va_list ap); /* Using argc and argv */ void *valkeyClusterCommandArgv(valkeyClusterContext *cc, int argc, const char **argv, const size_t *argvlen); @@ -248,6 +251,9 @@ int valkeyClusterAppendCommandToNode(valkeyClusterContext *cc, /* Variadic using va_list */ int valkeyClustervAppendCommand(valkeyClusterContext *cc, const char *format, va_list ap); +int valkeyClustervAppendCommandToNode(valkeyClusterContext *cc, + valkeyClusterNode *node, + const char *format, va_list ap); /* Using argc and argv */ int valkeyClusterAppendCommandArgv(valkeyClusterContext *cc, int argc, const char **argv, const size_t *argvlen); diff --git a/src/valkeycluster.c b/src/valkeycluster.c index df877dcb..bf279667 100644 --- a/src/valkeycluster.c +++ b/src/valkeycluster.c @@ -2383,11 +2383,10 @@ void *valkeyClusterCommand(valkeyClusterContext *cc, const char *format, ...) { return reply; } -void *valkeyClusterCommandToNode(valkeyClusterContext *cc, - valkeyClusterNode *node, const char *format, - ...) { +void *valkeyClustervCommandToNode(valkeyClusterContext *cc, + valkeyClusterNode *node, const char *format, + va_list ap) { valkeyContext *c; - va_list ap; int ret; void *reply; int updating_slotmap = 0; @@ -2405,9 +2404,7 @@ void *valkeyClusterCommandToNode(valkeyClusterContext *cc, memset(cc->errstr, '\0', sizeof(cc->errstr)); } - va_start(ap, format); ret = valkeyvAppendCommand(c, format, ap); - va_end(ap); if (ret != VALKEY_OK) { valkeyClusterSetError(cc, c->err, c->errstr); @@ -2440,6 +2437,19 @@ void *valkeyClusterCommandToNode(valkeyClusterContext *cc, return reply; } +void *valkeyClusterCommandToNode(valkeyClusterContext *cc, + valkeyClusterNode *node, const char *format, + ...) { + va_list ap; + valkeyReply *reply = NULL; + + va_start(ap, format); + reply = valkeyClustervCommandToNode(cc, node, format, ap); + va_end(ap); + + return reply; +} + void *valkeyClusterCommandArgv(valkeyClusterContext *cc, int argc, const char **argv, const size_t *argvlen) { valkeyReply *reply = NULL; @@ -2544,11 +2554,10 @@ int valkeyClusterAppendCommand(valkeyClusterContext *cc, const char *format, return ret; } -int valkeyClusterAppendCommandToNode(valkeyClusterContext *cc, - valkeyClusterNode *node, - const char *format, ...) { +int valkeyClustervAppendCommandToNode(valkeyClusterContext *cc, + valkeyClusterNode *node, + const char *format, va_list ap) { valkeyContext *c; - va_list ap; struct cmd *command = NULL; char *cmd = NULL; int len; @@ -2569,10 +2578,7 @@ int valkeyClusterAppendCommandToNode(valkeyClusterContext *cc, return VALKEY_ERR; } - /* Allocate cmd and encode the variadic command */ - va_start(ap, format); len = valkeyvFormatCommand(&cmd, format, ap); - va_end(ap); if (len == -1) { goto oom; @@ -2611,6 +2617,23 @@ int valkeyClusterAppendCommandToNode(valkeyClusterContext *cc, return VALKEY_ERR; } +int valkeyClusterAppendCommandToNode(valkeyClusterContext *cc, + valkeyClusterNode *node, + const char *format, ...) { + int ret; + va_list ap; + + if (cc == NULL || node == NULL || format == NULL) { + return VALKEY_ERR; + } + + va_start(ap, format); + ret = valkeyClustervAppendCommandToNode(cc, node, format, ap); + va_end(ap); + + return ret; +} + int valkeyClusterAppendCommandArgv(valkeyClusterContext *cc, int argc, const char **argv, const size_t *argvlen) { int ret;