static gchar *cache_db = NULL;
static gchar *redis_db = NULL;
static gchar *redis_password = NULL;
+static gboolean reset_previous = FALSE;
static void rspamadm_statconvert (gint argc, gchar **argv);
static const char *rspamadm_statconvert_help (gboolean full_help);
"Database in redis (should be numeric)", NULL},
{"password", 'p', 0, G_OPTION_ARG_STRING, &redis_password,
"Password to connect to redis", NULL},
+ {"reset", 'r', 0, G_OPTION_ARG_NONE, &reset_previous,
+ "Reset previous data instead of appending values", NULL},
{NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL}
};
"-s: symbol in redis (e.g. BAYES_SPAM)\n"
"-c: also convert data from the learn cache\n"
"-D: output redis database\n"
- "-p: redis password\n";
+ "-p: redis password\n"
+ "-r: reset previous data instead of increasing values\n";
}
else {
help_str = "Convert statistics from sqlite3 to redis";
"redis_host", 0, false);
ucl_object_insert_key (obj, ucl_object_fromstring (symbol),
"symbol", 0, false);
+ ucl_object_insert_key (obj, ucl_object_frombool (reset_previous),
+ "reset_previous", 0, false);
if (cache_db != NULL) {
ucl_object_insert_key (obj, ucl_object_fromstring (cache_db),
local redis = require "rspamd_redis"
local util = require "rspamd_util"
-local function send_redis(server, symbol, tokens, password, db)
+local function send_redis(server, symbol, tokens, password, db, cmd)
local ret = true
local conn,err = redis.connect_sync({
host = server,
end
for _,t in ipairs(tokens) do
- if not conn:add_cmd('HINCRBY', {symbol .. t[3], t[1], t[2]}) then
+ if not conn:add_cmd(cmd, {symbol .. t[3], t[1], t[2]}) then
ret = false
end
end
local redis_password = res['redis_password']
local redis_db = res['redis_db']
local ret = false
+ local cmd = 'HINCRBY'
+
+ if res['reset_previous'] then
+ cmd = 'HSET'
+ end
if res['cache_db'] then
if not convert_learned(res['cache_db'], res['redis_host']) then
total = total + 1
if num > lim then
if not send_redis(res['redis_host'], res['symbol'],
- tokens, redis_password, redis_db) then
+ tokens, redis_password, redis_db, cmd) then
print('Cannot send tokens to the redis server')
return
end
if #tokens > 0 and
not send_redis(res['redis_host'], res['symbol'], tokens,
- redis_password, redis_db) then
+ redis_password, redis_db, cmd) then
print('Cannot send tokens to the redis server')
return
for id,learned in pairs(learns) do
local user = users_map[id]
- if not conn:add_cmd('HINCRBY', {res['symbol'] .. user, 'learns', learned}) then
+ if not conn:add_cmd(cmd, {res['symbol'] .. user, 'learns', learned}) then
print('Cannot update learns for user: ' .. user)
end
end