Status::Hash: Reduce redis round-trips #139
Open
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
&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 toexpire
was unnecessary, we can useset
orsetex
instead, or, ideally, if we were ok with supporting only redis2.6.12+, we could switch to
set
with theex
option.Finally, in
remove
, we can also wrapdel
andzrem
for the samereasons we wrapped the two calls in
create
.The use of
pipelined
andmulti
is 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"