Skip to content

Commit

Permalink
Merge pull request #93 from CahidArda/rate-limit-fix
Browse files Browse the repository at this point in the history
fix sliding window and bucket scripts
  • Loading branch information
ogzhanolguncu authored Apr 3, 2024
2 parents b0fa586 + 3bf3ea2 commit 53a9d51
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion examples/with-vercel-kv/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Ratelimit } from "../../../src";
import { Ratelimit } from "@upstash/ratelimit";
import kv from "@vercel/kv";
import { Inter } from "next/font/google";
import { headers } from "next/headers";
Expand Down
4 changes: 2 additions & 2 deletions src/lua-scripts/single.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const slidingWindowScript = `
end
local percentageInCurrent = ( now % window ) / window
-- weighted requests to consider from the previous window
requestsInPreviousWindow = math.floor(( incrementBy - percentageInCurrent ) * requestsInPreviousWindow)
requestsInPreviousWindow = math.floor(( 1 - percentageInCurrent ) * requestsInPreviousWindow)
if requestsInPreviousWindow + requestsInCurrentWindow >= tokens then
return -1
end
Expand Down Expand Up @@ -87,7 +87,7 @@ export const tokenBucketScript = `
`;

export const cachedFixedWindowScript = `
local key = KEYS[1
local key = KEYS[1]
local window = ARGV[1]
local incrementBy = ARGV[2] -- increment rate per request at a given value, default is 1
Expand Down

0 comments on commit 53a9d51

Please sign in to comment.