From d61a9525f01ef6a410d34c5132294de21fdb4ca0 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 18 Aug 2016 14:18:04 +0100 Subject: [PATCH] [Feature] Read redis backend statistics configuration from global section Issue: #766 --- src/libstat/backends/redis_backend.c | 20 ++++++++++++++++++++ src/libstat/learn_cache/redis_cache.c | 21 +++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/libstat/backends/redis_backend.c b/src/libstat/backends/redis_backend.c index 83517ba64..4ff9b08b1 100644 --- a/src/libstat/backends/redis_backend.c +++ b/src/libstat/backends/redis_backend.c @@ -1050,6 +1050,26 @@ rspamd_redis_init (struct rspamd_stat_ctx *ctx, stf->symbol); } + /* Now try global redis settings */ + if (!ret) { + obj = ucl_object_lookup (cfg->rcl_obj, "redis"); + + if (obj) { + const ucl_object_t *specific_obj; + + specific_obj = ucl_object_lookup (obj, "statistics"); + + if (specific_obj) { + ret = rspamd_redis_try_ucl (backend, specific_obj, cfg, + stf->symbol); + } + else { + ret = rspamd_redis_try_ucl (backend, obj, cfg, + stf->symbol); + } + } + } + if (!ret) { msg_err_config ("cannot init redis backend for %s", stf->symbol); g_slice_free1 (sizeof (*backend), backend); diff --git a/src/libstat/learn_cache/redis_cache.c b/src/libstat/learn_cache/redis_cache.c index 473bee8ec..cd92bfac4 100644 --- a/src/libstat/learn_cache/redis_cache.c +++ b/src/libstat/learn_cache/redis_cache.c @@ -320,6 +320,27 @@ rspamd_stat_cache_redis_init (struct rspamd_stat_ctx *ctx, stf->symbol); } + /* Now try global redis settings */ + if (!ret) { + obj = ucl_object_lookup (cfg->rcl_obj, "redis"); + + if (obj) { + const ucl_object_t *specific_obj; + + specific_obj = ucl_object_lookup (obj, "statistics"); + + if (specific_obj) { + ret = rspamd_redis_cache_try_ucl (cache_ctx, specific_obj, cfg, + stf->symbol); + } + else { + ret = rspamd_redis_cache_try_ucl (cache_ctx, obj, cfg, + stf->symbol); + } + } + } + + if (!ret) { msg_err_config ("cannot init redis cache for %s", stf->symbol); g_slice_free1 (sizeof (*cache_ctx), cache_ctx); -- 2.39.5