Status::Hash: Reduce redis round-trips - #139
Open
pjambet wants to merge 1 commit into
Open
Conversation
The calls to `zadd` & `zremrangebyscore` should be consistent, that is, we don't one want to succeed and one to fail. On top of that, we can send both at once to prevent one roundtrip. In `set`, the call to `expire` was unnecessary, we can use `set` or `setex` instead, or, ideally, if we were ok with supporting only redis 2.6.12+, we could switch to `set` with the `ex` option. Finally, in `remove`, we can also wrap `del` and `zrem` for the same reasons we wrapped the two calls in `create`. The use of `pipelined` and `multi` is a bit verbose, and technically unnecessary since the ruby gem drops the multi/exec calls within a pipelined call, and a multi call by itself uses pipelining, but doing it as such is more explicit wrt intent: "We want to wrap these in a transaction for the sake of atomicity, and we might as well optimize the network calls, and let Redis be faster as well, by pipelining the whole thing"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The calls to
zadd&zremrangebyscoreshould be consistent, that is,we don't one want to succeed and one to fail. On top of that, we can
send both at once to prevent one roundtrip.
In
set, the call toexpirewas unnecessary, we can usesetorsetexinstead, or, ideally, if we were ok with supporting only redis2.6.12+, we could switch to
setwith theexoption.Finally, in
remove, we can also wrapdelandzremfor the samereasons we wrapped the two calls in
create.The use of
pipelinedandmultiis a bit verbose, and technicallyunnecessary since the ruby gem drops the multi/exec calls within a
pipelined call, and a multi call by itself uses pipelining, but doing it
as such is more explicit wrt intent:
"We want to wrap these in a transaction for the sake of atomicity, and
we might as well optimize the network calls, and let Redis be faster as
well, by pipelining the whole thing"