apisix
apisix copied to clipboard
feat(limit-count): add sliding window support for redis-based policies
Description
This PR introduces sliding window support to the limit-count plugin for Redis- and Redis Cluster–based policies while preserving the existing fixed window behavior by default.
- Adds a new
window_typeoption (fixed|sliding) to thelimit-countplugin configuration, withfixedas the default for backward compatibility. - Enforces that
window_type = "sliding"is only allowed when thepolicyisredisorredis-clusterto avoid unsupported combinations. - Extends the Redis (
limit-count-redis) and Redis Cluster (limit-count-redis-cluster) implementations to enforce an exact N requests per rolling time window whenwindow_typeis set tosliding. - Adds test cases for the sliding window behavior in both Redis and Redis Cluster modes (
limit-count-redis-sliding.t,limit-count-redis-cluster-sliding.t). - Updates the English and Chinese
limit-countplugin documentation to describe the newwindow_typeoption, its behavior, and performance considerations when using sliding windows.
The default behavior remains unchanged for existing configurations that do not specify window_type or continue to use fixed.
Which issue(s) this PR fixes:
Fixes #
Checklist
- [x] I have explained the need for this PR and the problem it solves
- [x] I have explained the changes or the new features added to this PR
- [x] I have added tests corresponding to this change
- [x] I have updated the documentation to reflect this change
- [x] I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)