Comments (14)
I think your understanding is correct. I read your test code and it should work like this.
from asgi-ratelimit.
If there are any bugs here, PR is welcome.
from asgi-ratelimit.
If there are any bugs here, PR is welcome.
not sure where to look at to be honest, I'd suppose at first sight in the calc_incr_value
method ? I see incr_dict
has its keys decremented by 1, should there be a global count in case there are multiple limits ?
I also note that the decrease_limit
script always returns None when running the test_redis, but I don't understand well the logic behind this.
Would you explain briefly the logic behind, I'd be ok trying to fix this but I'd need some guidance before :)
from asgi-ratelimit.
I also note that the
decrease_limit
script always returns None when running the test_redis, but I don't understand well the logic behind this.
decrease_limit
is an atomic operation. It returns True after successfully decrementing all keys by 1, otherwise it returns False. It shouldn't return None in design, can you tell me how to reproduce it to return None?
from asgi-ratelimit.
I just issued a draft PR so that you see it, it's not meant to be a PR but I figured it was quicker than to copy-paste stuff
from asgi-ratelimit.
This is so strange that such behavior shouldn't happen. It seems that aredis failed to execute the Lua script but did not throw an exception, only returning None.
from asgi-ratelimit.
aredis
's author seems to be busy with 996 work. I think it's time to switch to another asynchronous redis driver.
from asgi-ratelimit.
aredis
's author seems to be busy with 996 work. I think it's time to switch to another asynchronous redis driver.
I was looking at the landscape the other day and it's a landmine @abersheeran !
What I can say: I use arq, which uses aioredis without sweating, but this is limited knowledge, I'll ask at arq given the paragraph below what they think they'll do:
it seems aioredis went unmaintaned for a while, then back up, then this PR seems to indicate a fork to come to aioredis-py which will be a total rewrite based more on redis-py, and aioredis will likely come back to sleep mode.
Hard to choose
from asgi-ratelimit.
I agree. Hard to choose.
Back to asgi-ratelimit. We need to verify my guess: whether the lua script is running normally first. But I'm a bit busy, can you help me verify it?
from asgi-ratelimit.
from asgi-ratelimit.
ok I think your guess is correct, seems like the lua script is the culprit and doesn't work as intended, I base this on implementing a quick and dirty branch based on aioredis and it returns also None every time as well: https://github.com/euri10/asgi-ratelimit/tree/aioredis
now my lua knowledge is very low :) will try to see what goes wrong as well,
from asgi-ratelimit.
Thank you for your help! I just need to focus on this lua script next. Maybe I can fix it these days.
from asgi-ratelimit.
from the docs https://redis.io/commands/eval
it seems the return false in the decrease script is the culprit:
Lua boolean false -> Redis Nil bulk reply.
from asgi-ratelimit.
changing the script to
DECREASE_SCRIPT = """
for i, key in ipairs(KEYS) do
local value = tonumber(redis.call('GET', key))
if not value or value < 1 then
return 0
end
end
for i, key in ipairs(KEYS) do
redis.call('DECR', key)
end
return 1
"""
solves the None issue, but does not change the outcome of the test, so there's something else going on
from asgi-ratelimit.
Related Issues (20)
- path matching breaks on 1st match HOT 2
- feature: Retry-After header HOT 6
- feature: custom 429 per limit HOT 1
- feature: gcra algorithm HOT 1
- Exclude certain paths? HOT 2
- docs: custom block needs to be adapted HOT 2
- Any way to get apply limit on entire app or a group of endpoints HOT 8
- ιζ±η±»issue
- customize user and group key HOT 1
- The wrong ttl
- release v0.6.1 and publish HOT 1
- Ratelimit user_id for JWT access token , IP address for endpoint having not token.
- Please release 0.7.0 HOT 1
- init ratelimiter backend from config, not code
- Zero rating behaviour in MemoryBackend, blocking abusive clients as part of rate limiting HOT 1
- feature: Redis, more params to support ssl connect HOT 2
- Wrong import in example HOT 1
- Add type hint annotations
- Rate limit per request method HOT 12
- New Version Release HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from asgi-ratelimit.