Skip to content

enable allowN and allowAtMost to peek at contents #47

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

Merged
merged 4 commits into from
Jan 14, 2021

Conversation

danehammer
Copy link
Contributor

@danehammer danehammer commented Jan 13, 2021

If the caller wants to check what's there without mutating it, the lua script doesn't allow it when the row doesn't yet exist, because it tries to set a new row with an expiry of zero. This causes an error like:

ERR Error running script (call to f_b51fcf1fec2622e401ecd1495ba719a525362891): @user_script:54: ERR invalid expire time in set 

I think this approach is in line with what was suggested on #32 -- I changed both scripts to only try and set if the expiry ends up being greater than zero. This should preserve any existing functionality while also re-introducing the ability to peek at rows without altering them. This addresses the case where the row isn't there.

In past versions of redis_rate, you could peek at the current state
in the redis limiter by calling allowN but not incrementing. The
move to lua script did not preserve this (unadvertised) ability.

This adds it back, the only issue was trying to SET a redis
row with an expiry of zero if the row didn't exist. Since the
caller doesn't want to increment at all, this changes the SET
to not be called if the value is absent.
@vmihailenco
Copy link
Member

Looks pretty neat - thanks 👍

@vmihailenco vmihailenco merged commit c52e4fd into go-redis:v9 Jan 14, 2021
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