Split redisCommand to a more generic function
This commit is contained in:
parent
510bbf1721
commit
81f6b8ffd4
13
hiredis.c
13
hiredis.c
@ -538,8 +538,7 @@ static void addArgument(sds a, char ***argv, int *argc) {
|
|||||||
* Finally when type is REDIS_REPLY_INTEGER the long long integer is
|
* Finally when type is REDIS_REPLY_INTEGER the long long integer is
|
||||||
* stored at reply->integer.
|
* stored at reply->integer.
|
||||||
*/
|
*/
|
||||||
redisReply *redisCommand(int fd, const char *format, ...) {
|
static sds redisFormatCommand(const char *format, va_list ap) {
|
||||||
va_list ap;
|
|
||||||
size_t size;
|
size_t size;
|
||||||
const char *arg, *c = format;
|
const char *arg, *c = format;
|
||||||
sds cmd = sdsempty(); /* whole command buffer */
|
sds cmd = sdsempty(); /* whole command buffer */
|
||||||
@ -548,7 +547,6 @@ redisReply *redisCommand(int fd, const char *format, ...) {
|
|||||||
int argc = 0, j;
|
int argc = 0, j;
|
||||||
|
|
||||||
/* Build the command string accordingly to protocol */
|
/* Build the command string accordingly to protocol */
|
||||||
va_start(ap,format);
|
|
||||||
while(*c != '\0') {
|
while(*c != '\0') {
|
||||||
if (*c != '%' || c[1] == '\0') {
|
if (*c != '%' || c[1] == '\0') {
|
||||||
if (*c == ' ') {
|
if (*c == ' ') {
|
||||||
@ -578,7 +576,6 @@ redisReply *redisCommand(int fd, const char *format, ...) {
|
|||||||
}
|
}
|
||||||
c++;
|
c++;
|
||||||
}
|
}
|
||||||
va_end(ap);
|
|
||||||
|
|
||||||
/* Add the last argument if needed */
|
/* Add the last argument if needed */
|
||||||
if (sdslen(current) != 0)
|
if (sdslen(current) != 0)
|
||||||
@ -595,6 +592,14 @@ redisReply *redisCommand(int fd, const char *format, ...) {
|
|||||||
sdsfree(argv[j]);
|
sdsfree(argv[j]);
|
||||||
}
|
}
|
||||||
free(argv);
|
free(argv);
|
||||||
|
}
|
||||||
|
|
||||||
|
redisReply *redisCommand(int fd, const char *format, ...) {
|
||||||
|
va_list ap;
|
||||||
|
sds cmd;
|
||||||
|
va_start(ap,format);
|
||||||
|
cmd = redisFormatCommand(format,ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
/* Send the command via socket */
|
/* Send the command via socket */
|
||||||
anetWrite(fd,cmd,sdslen(cmd));
|
anetWrite(fd,cmd,sdslen(cmd));
|
||||||
|
Loading…
Reference in New Issue
Block a user