Skip to content

Commit 984e8aa

Browse files
committed
feat: add window_type for limit-count
Signed-off-by: Sihyeon Jang <[email protected]>
1 parent 00f18aa commit 984e8aa

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

apisix/plugins/limit-count/init.lua

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ local schema = {
7272
properties = {
7373
count = {type = "integer", exclusiveMinimum = 0},
7474
time_window = {type = "integer", exclusiveMinimum = 0},
75+
window_type = {
76+
type = "string",
77+
enum = {"fixed", "sliding"},
78+
default = "fixed",
79+
},
7580
group = {type = "string"},
7681
key = {type = "string", default = "remote_addr"},
7782
key_type = {type = "string",
@@ -137,6 +142,12 @@ function _M.check_schema(conf, schema_type)
137142
return false, err
138143
end
139144

145+
if (not conf.policy or conf.policy == "local")
146+
and conf.window_type and conf.window_type ~= "fixed"
147+
then
148+
return false, "window_type \"sliding\" is only supported when policy is \"redis\" or \"redis-cluster\""
149+
end
150+
140151
if conf.group then
141152
-- means that call by some plugin not support
142153
if conf._vid then
@@ -184,12 +195,12 @@ local function create_limit_obj(conf, plugin_name)
184195

185196
if conf.policy == "redis" then
186197
return limit_redis_new("plugin-" .. plugin_name,
187-
conf.count, conf.time_window, conf)
198+
conf.count, conf.time_window, conf.window_type, conf)
188199
end
189200

190201
if conf.policy == "redis-cluster" then
191202
return limit_redis_cluster_new("plugin-" .. plugin_name, conf.count,
192-
conf.time_window, conf)
203+
conf.time_window, conf.window_type, conf)
193204
end
194205

195206
return nil

0 commit comments

Comments
 (0)