ExHammer / hammer-backend-redis

A Redis backend for for the Hammer rate-limiter
https://hexdocs.pm/ExHammer/hammer-backend-redis
MIT License
50 stars 32 forks source link

Return count upon bucket creation #16

Closed davelively14 closed 5 years ago

davelively14 commented 5 years ago

Calling do_count_hit will return {:ok, count} if the bucket was already created. If a bucket needed to be created (i.e. the first time this is called), do_count_hit would always return {:ok, 1}.

The counts are stored correctly, but the initial return is misleading. Here's an example of what we have in production.

First call costs 30, but since {:ok, 1} was returned, we let the user know that they still have 599 points left: image

The next call also costs 30, but since {:ok, 60} was returned, we're able to correctly inform the user of the cost: image

coveralls commented 5 years ago

Coverage Status

Coverage remained the same at 80.357% when pulling 913e78cd417deeafc050d48eff472d5f5dcf6238 on davelively14:dl-return-increment-on-create into 8cc4a28a2debcc6448a29d86b6c787d3f7289527 on ExHammer:master.

JuneKelly commented 5 years ago

Good catch, thanks!

JuneKelly commented 5 years ago

I'll try to get this merged and released this week.

davelively14 commented 5 years ago

I'll try to get this merged and released this week.

Awesome, thanks so much and thanks for Hammer!

JuneKelly commented 5 years ago

Published as version 6.1