Skip to content

Conversation

@sihyeonn
Copy link

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_type option (fixed | sliding) to the limit-count plugin configuration, with fixed as the default for backward compatibility.
  • Enforces that window_type = "sliding" is only allowed when the policy is redis or redis-cluster to 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 when window_type is set to sliding.
  • 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-count plugin documentation to describe the new window_type option, 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

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

@dosubot dosubot bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Nov 18, 2025
@sihyeonn sihyeonn changed the title eat(limit-count): add sliding window support for redis-based policies feat(limit-count): add sliding window support for redis-based policies Nov 18, 2025
@dosubot dosubot bot added the enhancement New feature or request label Nov 18, 2025
end
for i = 1, cost do
redis.call('ZADD', KEYS[1], now, now .. ':' .. i)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In high-concurrency scenarios, uniqueness may not be guaranteed. I think we can utilize ngx.var.request_id

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants