Added increment_ratelimit
I added an increment_ratelimit function to just increment the group ratelimit count.
This is practically just an alias of is_ratelimited but makes more sense in terms of its name. Takes only request and group (should I add keys, and fn too?) and returns the count of limits on return (can be a boolean True if successful instead if preferred). This was suggested in #308 as it makes more logical sense to call a function to "increment" the ratelimit rather than call "is_ratelimited" if you're just incrementing it.
Where would this be useful? Well in situations like unsuccessful login attempts, in the logic for your function you may want to add 1 to the count (in this case you dont use decorators), so you need to call a function.
increment_ratelimit("unsuccessful_login")
This snippet makes a little more sense then this snippet (logically)
is_ratelimited(request, group="unsuccessful_login", key="ip", rate="5/5m", increment=True)
Closes issue: #308
(converting to draft as I have not yet been able to run the tests, I'll try again when I get home just to make sure it passes and works fine)
Hi @jsocol,
I have added the increment_ratelimit function in the core file. I have also included a new test (test_increment_ratelimit) and added some documentation for this addition as well.
view documentation image
Thanks
Note: I couldn't manage to get it to work without the rate, method and key so I've left them in. My original idea was to not have to use any of them though - so is this still okay? The only difference between this and "is_ratelimited" is that increment is true by default and it has a better name.
Thanks @jaap3 😄