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
Optimize increment and decrement for RedisCacheStore
#45711
Optimize increment and decrement for RedisCacheStore
#45711
Conversation
@fatkodima thanks for the PR, and I'm in favor of this improvement, however I'm afraid there's a bit too much unrelated and not strictly necessary changes. Not saying they're not desirable, but it would make it much easier if this PR was really only focused on the pipelining change. The state of the code makes me think we should really refactor all this so that |
2a5f98f
to
8673130
Compare
@byroot Thanks for the review. Agreed. That changes were left from my original implementation, now they are not needed. |
8673130
to
1ceb596
Compare
1ceb596
to
412f137
Compare
@byroot Rebased on top of the refactoring with the #45711 (comment) suggestion. Let me know if some other changes needed. |
412f137
to
e35eb0f
Compare
Before this PR, when incrementing/decrementing a counter with
:expires_in
option, we will make 3 requests to Redis.increment
/decrement
, for example, is very heavily used byrack-attack
- https://github.com/rack/rack-attack/blob/95ce9fdd7c99a527a46ffc477b01e682fed48dce/lib/rack/attack/store_proxy/redis_cache_store_proxy.rb#L13-L25 (that implementation currently also makes redundant calls and works around unsupportedexpires_in
in older versions; the implementation should just use the native implementation from rails in the future). Increment can be called several times per request (for each throttling rule).With this PR, we will make only 1 pipelined request, if possible.
cc @byroot