diff --git a/examples/with-vercel-kv/app/page.tsx b/examples/with-vercel-kv/app/page.tsx index 2d8dce4..62e7cf3 100644 --- a/examples/with-vercel-kv/app/page.tsx +++ b/examples/with-vercel-kv/app/page.tsx @@ -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"; diff --git a/src/lua-scripts/single.ts b/src/lua-scripts/single.ts index 3582e69..a1f0812 100644 --- a/src/lua-scripts/single.ts +++ b/src/lua-scripts/single.ts @@ -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 @@ -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