summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPieter Noordhuis <pcnoordhuis@gmail.com>2010-09-24 14:18:30 +0200
committerPieter Noordhuis <pcnoordhuis@gmail.com>2010-09-24 18:42:21 +0200
commit81f6b8ffd42460038e3b9498e7a60347eef1fcd4 (patch)
treebe8b3e44482916980d5e9bc7aa40d3d2f6f9c2f1
parent510bbf17210890a02b043dd2293c03ffd0637d79 (diff)
Split redisCommand to a more generic function
-rw-r--r--hiredis.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/hiredis.c b/hiredis.c
index 084561c..6ab8063 100644
--- a/hiredis.c
+++ b/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
* stored at reply->integer.
*/
-redisReply *redisCommand(int fd, const char *format, ...) {
- va_list ap;
+static sds redisFormatCommand(const char *format, va_list ap) {
size_t size;
const char *arg, *c = format;
sds cmd = sdsempty(); /* whole command buffer */
@@ -548,7 +547,6 @@ redisReply *redisCommand(int fd, const char *format, ...) {
int argc = 0, j;
/* Build the command string accordingly to protocol */
- va_start(ap,format);
while(*c != '\0') {
if (*c != '%' || c[1] == '\0') {
if (*c == ' ') {
@@ -578,7 +576,6 @@ redisReply *redisCommand(int fd, const char *format, ...) {
}
c++;
}
- va_end(ap);
/* Add the last argument if needed */
if (sdslen(current) != 0)
@@ -595,6 +592,14 @@ redisReply *redisCommand(int fd, const char *format, ...) {
sdsfree(argv[j]);
}
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 */
anetWrite(fd,cmd,sdslen(cmd));