Skip to content

Commit

Permalink
Merge pull request elastic#25 from balabit/merge/f/redis-argv
Browse files Browse the repository at this point in the history
Small Redis improvements
  • Loading branch information
bazsi committed Dec 2, 2013
2 parents 5d63c7e + aafbc37 commit 86303cd
Showing 1 changed file with 27 additions and 16 deletions.
43 changes: 27 additions & 16 deletions modules/redis/redis.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ typedef struct

LogTemplateOptions template_options;

gchar *command;
GString *command;
LogTemplate *key;
GString *key_str;
LogTemplate *param1;
Expand Down Expand Up @@ -83,8 +83,7 @@ redis_dd_set_command(LogDriver *d, const gchar *command,
{
RedisDriver *self = (RedisDriver *)d;

g_free(self->command);
self->command = g_strdup(command);
g_string_assign(self->command, command);

log_template_unref(self->key);
self->key = log_template_ref(key);
Expand Down Expand Up @@ -183,6 +182,9 @@ redis_worker_insert(LogThrDestDriver *s)
LogMessage *msg;
LogPathOptions path_options = LOG_PATH_OPTIONS_INIT;
redisReply *reply;
const char *argv[5];
size_t argvlen[5];
int argc = 2;

redis_dd_connect(self, TRUE);

Expand All @@ -205,23 +207,30 @@ redis_worker_insert(LogThrDestDriver *s)
log_template_format(self->param2, msg, &self->template_options, LTZ_SEND,
self->seq_num, NULL, self->param2_str);

if (!self->param2)
argv[0] = self->command->str;
argvlen[0] = self->command->len;
argv[1] = self->key_str->str;
argvlen[1] = self->key_str->len;

if (self->param1)
{
if (!self->param1)
reply = redisCommand(self->c,"%s %s", self->command,
self->key_str->str);
else
reply = redisCommand(self->c,"%s %s %s", self->command,
self->key_str->str, self->param1_str->str);
argv[2] = self->param1_str->str;
argvlen[2] = self->param1_str->len;
argc++;
}

if (self->param2)
{
argv[3] = self->param2_str->str;
argvlen[3] = self->param2_str->len;
argc++;
}
else
reply = redisCommand(self->c,"%s %s %s %s", self->command,
self->key_str->str, self->param1_str->str,
self->param2_str);

reply = redisCommandArgv(self->c, argc, argv, argvlen);

msg_debug("REDIS command sent",
evt_tag_str("driver", self->super.super.super.id),
evt_tag_str("command", self->command),
evt_tag_str("command", self->command->str),
evt_tag_str("key", self->key_str->str),
evt_tag_str("param1", self->param1_str->str),
evt_tag_str("param2", self->param2_str->str),
Expand Down Expand Up @@ -305,7 +314,7 @@ redis_dd_free(LogPipe *d)
log_template_options_destroy(&self->template_options);

g_free(self->host);
g_free(self->command);
g_string_free(self->command, TRUE);
log_template_unref(self->key);
log_template_unref(self->param1);
log_template_unref(self->param2);
Expand Down Expand Up @@ -340,6 +349,8 @@ redis_dd_new(GlobalConfig *cfg)
redis_dd_set_host((LogDriver *)self, "127.0.0.1");
redis_dd_set_port((LogDriver *)self, 6379);

self->command = g_string_sized_new(32);

init_sequence_number(&self->seq_num);
log_template_options_defaults(&self->template_options);

Expand Down

0 comments on commit 86303cd

Please sign in to comment.