Skip to content
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

Store increments in Redis #269

Closed
alexsnaps opened this issue Mar 20, 2024 · 0 comments · Fixed by #281
Closed

Store increments in Redis #269

alexsnaps opened this issue Mar 20, 2024 · 0 comments · Fixed by #281

Comments

@alexsnaps
Copy link
Member

Currently we store decrements in Redis. We first store the limit's threshold on miss and then decrement

Current SCRIPT_UPDATE_COUNTER script:

local set_res = redis.call('set', KEYS[1], ARGV[1], 'EX', ARGV[2], 'NX')
redis.call('incrby', KEYS[1], - ARGV[3])
if set_res then
    redis.call('sadd', KEYS[2], KEYS[1])
end

The idea is to completely decouple the counter from the limit and only store what happened, i.e. increments from 0
Something along these lines:

local c = redis.call('incrby', KEYS[1], ARGV[2])
if c == ARGV[2] then
  redis.call('expire', KEYS[1], ARGV[1], 'NX')
  redis.call('sadd', KEYS[2], KEYS[1])
end
return c

Let's introduce this as another script and try leveraging it in our both our (Async)CounterStorages

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant