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 #281

Merged
merged 2 commits into from
Mar 26, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion limitador/src/storage/redis/scripts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
pub const SCRIPT_UPDATE_COUNTER: &str = "
local c = redis.call('incrby', KEYS[1], ARGV[2])
if c == tonumber(ARGV[2]) then
redis.call('expire', KEYS[1], ARGV[1], 'NX')
redis.call('expire', KEYS[1], ARGV[1])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to redis doc https://redis.io/commands/expire/

History

    Starting with Redis version 7.0.0: Added options: NX, XX, GT and LT.

So, removing the NX option to keep compatibility with redis 5 and redi 6.

Actually, I think it is not needed, as the key has just been created, so expiration has not been set. This happens within the context of the script, so no race condition issues can hit here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strictly speaking we indeed don't need it...

redis.call('sadd', KEYS[2], KEYS[1])
end
return c";
Expand Down
Loading