aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-01-08 15:46:31 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-01-08 15:46:31 +0000
commit56659c6655ac676ace736ae419554d71057ce08e (patch)
treeb288d698836643754c8a89dd4b3d8d39dceffdc1
parent7d4eb6418d9c98b042eac64107e099f402bfd33e (diff)
downloadrspamd-56659c6655ac676ace736ae419554d71057ce08e.tar.gz
rspamd-56659c6655ac676ace736ae419554d71057ce08e.zip
Fix redis queries
-rw-r--r--src/libstat/backends/redis_backend.c51
1 files changed, 35 insertions, 16 deletions
diff --git a/src/libstat/backends/redis_backend.c b/src/libstat/backends/redis_backend.c
index 8863fb8fe..e81d1b9eb 100644
--- a/src/libstat/backends/redis_backend.c
+++ b/src/libstat/backends/redis_backend.c
@@ -283,29 +283,42 @@ rspamd_redis_tokens_to_query (struct rspamd_task *task, GPtrArray *tokens,
rspamd_fstring_t *out;
rspamd_token_t *tok;
gchar n0[64], n1[64];
- guint i, l0, l1;
+ guint i, l0, l1, larg0, larg1;
guint64 num;
g_assert (tokens != NULL);
- l0 = strlen (arg0);
- l1 = strlen (arg1);
+ larg0 = strlen (arg0);
+ larg1 = strlen (arg1);
out = rspamd_fstring_sized_new (1024);
- rspamd_printf_fstring (&out, "*%d\r\n"
- "$%d\r\n"
- "%s\r\n"
- "$%d\r\n"
- "%s\r\n",
- learn ? (tokens->len * 2 + 2) : (tokens->len + 2),
- l0, arg0,
- l1, arg1);
+
+ if (!learn) {
+ rspamd_printf_fstring (&out, ""
+ "*%d\r\n"
+ "$%d\r\n"
+ "%s\r\n"
+ "$%d\r\n"
+ "%s\r\n",
+ learn ? (tokens->len * 2 + 2) : (tokens->len + 2),
+ larg0, arg0,
+ larg1, arg1);
+ }
for (i = 0; i < tokens->len; i ++) {
tok = g_ptr_array_index (tokens, i);
memcpy (&num, tok->data, sizeof (num));
- l0 = rspamd_snprintf (n0, sizeof (n0), "%uL", num);
if (learn) {
+ rspamd_printf_fstring (&out, ""
+ "*4\r\n"
+ "$%d\r\n"
+ "%s\r\n"
+ "$%d\r\n"
+ "%s\r\n",
+ larg0, arg0,
+ larg1, arg1);
+
+ l0 = rspamd_snprintf (n0, sizeof (n0), "%uL", num);
if (tok->values[idx] == (guint64)tok->values[idx]) {
l1 = rspamd_snprintf (n1, sizeof (n1), "%uL",
(guint64)tok->values[idx]);
@@ -315,11 +328,17 @@ rspamd_redis_tokens_to_query (struct rspamd_task *task, GPtrArray *tokens,
(guint64)tok->values[idx]);
}
- rspamd_printf_fstring (&out, "$%d\r\n%s\r\n"
- "$%d\r\n%s\r\n", l0, n0, l1, n1);
+ rspamd_printf_fstring (&out, ""
+ "$%d\r\n"
+ "%s\r\n"
+ "$%d\r\n"
+ "%s\r\n", l0, n0, l1, n1);
}
else {
- rspamd_printf_fstring (&out, "$%d\r\n%s\r\n", l0, n0);
+ l0 = rspamd_snprintf (n0, sizeof (n0), "%uL", num);
+ rspamd_printf_fstring (&out, ""
+ "$%d\r\n"
+ "%s\r\n", l0, n0);
}
}
@@ -762,7 +781,7 @@ rspamd_redis_learn_tokens (struct rspamd_task *task, GPtrArray *tokens,
rt->id = id;
query = rspamd_redis_tokens_to_query (task, tokens,
- "HMSET", rt->redis_object_expanded, TRUE, id);
+ "HINCRBYFLOAT", rt->redis_object_expanded, TRUE, id);
g_assert (query != NULL);
ret = redisAsyncFormattedCommand (rt->redis, rspamd_redis_learned, rt,