]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Ratelimit: support use of redis HSET for limits
authorAndrew Lewis <nerf@judo.za.org>
Wed, 30 Aug 2017 11:42:12 +0000 (13:42 +0200)
committerAndrew Lewis <nerf@judo.za.org>
Wed, 30 Aug 2017 11:42:12 +0000 (13:42 +0200)
.luacheckrc
lualib/lua_util.lua
src/plugins/lua/ratelimit.lua

index 07bbcea4d222b8553ab52796eed038d7d6b2df63..15ccdc229591fff45d920324e2e1ccdac71b4810 100644 (file)
@@ -41,6 +41,10 @@ files['/**/src/plugins/lua/greylist.lua'].globals = {
   'math.ifloor',
 }
 
+files['/**/lualib/lua_util.lua'].globals = {
+  'unpack',
+}
+
 files['/**/src/rspamadm/*'].globals = {
   'ansicolors',
   'getopt',
index 8479d579b0c3ed29600d487b97b141d16ff15925..a9abd901ad052326085e7574d4d90989cd354500 100644 (file)
@@ -144,4 +144,9 @@ exports.is_rspamc_or_controller = function(task)
   return is_rspamc
 end
 
+local unpack_function = table.unpack or unpack
+exports.unpack = function(t)
+  return unpack_function(t)
+end
+
 return exports
index b8d211ae7df0c98f98d2f6edd606868c67a7a6ba..e25ea42db321d742287deb304b4b8b413ca9f1fe 100644 (file)
@@ -38,6 +38,7 @@ local rl_prefix = 'RL'
 local ip_score_lower_bound = 10
 local ip_score_ham_multiplier = 1.1
 local ip_score_spam_divisor = 1.1
+local limits_hash
 
 local message_func = function(_, limit_type)
   return string.format('Ratelimit "%s" exceeded', limit_type)
@@ -511,13 +512,21 @@ local function ratelimit_cb(task)
         return process_buckets(task, args)
       end
     end
+    local params, method
+    if limits_hash then
+      params = {limits_hash, rspamd_lua_utils.unpack(redis_keys)}
+      method = 'HMGET'
+    else
+      method = 'MGET'
+      params = redis_keys
+    end
     local requested_keys = rspamd_redis_make_request(task,
       redis_params, -- connect params
       nil, -- hash key
       true, -- is write
       collect_cb, --callback
-      'MGET', -- command
-      redis_keys -- arguments
+      method, -- command
+      params -- arguments
     )
     if not requested_keys then
       rspamd_logger.errx(task, 'got error connecting to redis')
@@ -678,6 +687,10 @@ if opts then
     message_func = assert(load(opts['message_func']))()
   end
 
+  if opts['limits_hash'] then
+    limits_hash = opts['limits_hash']
+  end
+
   redis_params = rspamd_parse_redis_server('ratelimit')
   if not redis_params then
     rspamd_logger.infox(rspamd_config, 'no servers are specified, disabling module')