]> source.dussan.org Git - rspamd.git/commitdiff
Fix redis queries
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 8 Jan 2016 15:46:31 +0000 (15:46 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 8 Jan 2016 15:46:31 +0000 (15:46 +0000)
src/libstat/backends/redis_backend.c

index 8863fb8fed2454783fda2a79bb5699cfa39a0ae3..e81d1b9ebc72d681f545ba7ac5bbe1ead2d76eea 100644 (file)
@@ -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,