Skip to content

Commit

Permalink
redis: Turn self->command into a GString
Browse files Browse the repository at this point in the history
Since we need the length of the command on every insert, turn it into a
GString, so we will always have the length readily available.

Signed-off-by: Gergely Nagy <[email protected]>
  • Loading branch information
algernon committed Nov 30, 2013
1 parent f4774d3 commit aafbc37
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 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 @@ -208,8 +207,8 @@ redis_worker_insert(LogThrDestDriver *s)
log_template_format(self->param2, msg, &self->template_options, LTZ_SEND,
self->seq_num, NULL, self->param2_str);

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

Expand All @@ -231,7 +230,7 @@ redis_worker_insert(LogThrDestDriver *s)

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 @@ -315,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 @@ -350,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 aafbc37

Please sign in to comment.