abersheeran / asgi-ratelimit

A ASGI Middleware to rate limit
Apache License 2.0
292 stars 11 forks source link

Optimize lua code in default redis backend #15

Closed abersheeran closed 3 years ago

abersheeran commented 3 years ago

Related: #8 #9

euri10 commented 3 years ago

will go over it this week end for sure !

On Thu, Apr 1, 2021 at 5:21 AM Aber @.***> wrote:

@.**** commented on this pull request.

In tests/backends/test_redis.py https://github.com/abersheeran/asgi-ratelimit/pull/15#discussion_r605350464 :

  • app=rate_limit, base_url="http://testserver"
  • ) as client: # type: httpx.AsyncClient
  • multiple 1/s and 3/min

  • 1 3

  • response = await client.get(
  • "/multiple", headers={"user": "user", "group": "default"}
  • )
  • assert response.status_code == 200
  • 1-1 3-1 = 0 2

  • response = await client.get(
  • "/multiple", headers={"user": "user", "group": "default"}
  • )
  • assert response.status_code == 429
  • await asyncio.sleep(1)
  • 0+1 2+0 = 1 2

@euri10 https://github.com/euri10 Hey, after I re-read the code in detail and researched it, I found a problem. The two of us did not reach a consensus on the value deduction. In the original design, if the deduction fails, all values will not be deducted. Only when the deduction is successful, all values will be reduced by one.

I have submitted a new test and optimized the original code. Can you come and have a look when you are free?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/abersheeran/asgi-ratelimit/pull/15#pullrequestreview-625871312, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAINSPTFJ3RNO2QBMTCZNXLTGPREZANCNFSM42GD2UJA .

-- benoit barthelet http://pgp.mit.edu/pks/lookup?op=get&search=0xF150E01A72F6D2EE