Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Custom Rates #13

Merged
merged 1 commit into from
May 15, 2024
Merged

Adding Custom Rates #13

merged 1 commit into from
May 15, 2024

Conversation

CahidArda
Copy link
Collaborator

@CahidArda CahidArda commented May 14, 2024

With this change, it is now possible to rate limit with a custom rate:

from upstash_ratelimit import Ratelimit, FixedWindow
from upstash_redis import Redis

ratelimit = Ratelimit(
    redis=Redis.from_env(),
    limiter=FixedWindow(max_requests=10, window=10),
)

# pass rate as 5 to subtract 5 from the number of
# allowed requests in the window:
identifier = "api"
response = ratelimit.limit(identifier, rate=5)

Copied the lua scripts from the Typescript ratelimit repository. We had fixed some bugs there so I copied from there to have parity.

Copy link

linear bot commented May 14, 2024

@CahidArda CahidArda merged commit 70e1e41 into main May 15, 2024
1 check passed
@CahidArda CahidArda deleted the dx-899-add-custom-rates branch May 15, 2024 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants