diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2023-05-20 13:19:24 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rspamd.com> | 2023-05-20 13:19:24 +0100 |
commit | 32428449bd7a6035cecaaf4a684df997f2a9dab7 (patch) | |
tree | a9ec2043f4675f0d01361ef54ad5387a8c1e0445 /src/libserver/fuzzy_backend/fuzzy_backend_redis.c | |
parent | 6319622005f9da0cec9e255b8b8e4fe2721ced04 (diff) | |
download | rspamd-32428449bd7a6035cecaaf4a684df997f2a9dab7.tar.gz rspamd-32428449bd7a6035cecaaf4a684df997f2a9dab7.zip |
[Feature] Allow to have weak flags in fuzzy storage
Diffstat (limited to 'src/libserver/fuzzy_backend/fuzzy_backend_redis.c')
-rw-r--r-- | src/libserver/fuzzy_backend/fuzzy_backend_redis.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/libserver/fuzzy_backend/fuzzy_backend_redis.c b/src/libserver/fuzzy_backend/fuzzy_backend_redis.c index 0b7953bfe..390119fbc 100644 --- a/src/libserver/fuzzy_backend/fuzzy_backend_redis.c +++ b/src/libserver/fuzzy_backend/fuzzy_backend_redis.c @@ -1049,8 +1049,16 @@ rspamd_fuzzy_update_append_command (struct rspamd_fuzzy_backend *bk, g_string_append_len (key, cmd->digest, sizeof (cmd->digest)); value = g_string_sized_new (sizeof ("4294967296")); rspamd_printf_gstring (value, "%d", cmd->flag); - session->argv[cur_shift] = g_strdup ("HSET"); - session->argv_lens[cur_shift++] = sizeof ("HSET") - 1; + + if (cmd->version & RSPAMD_FUZZY_FLAG_WEAK) { + session->argv[cur_shift] = g_strdup ("HSETNX"); + session->argv_lens[cur_shift++] = sizeof ("HSETNX") - 1; + } + else { + session->argv[cur_shift] = g_strdup ("HSET"); + session->argv_lens[cur_shift++] = sizeof ("HSET") - 1; + } + session->argv[cur_shift] = key->str; session->argv_lens[cur_shift++] = key->len; session->argv[cur_shift] = g_strdup ("F"); @@ -1445,7 +1453,7 @@ rspamd_fuzzy_backend_update_redis (struct rspamd_fuzzy_backend *bk, /* * For each normal hash addition we do 3 redis commands: - * HSET <key> F <flag> + * HSET <key> F <flag> **OR** HSETNX <key> F <flag> when flag is weak * HINCRBY <key> V <weight> * EXPIRE <key> <expire> * INCR <prefix||fuzzy_count> |