Add Redis::Distributed#mset_nonatomic
& mapped_mset_nonatomic
#1215
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.
Redis::Distributed#mset
can't be guaranteed to be atomic, so it raises CannotDistribute by default.However, sometimes we don't care so much about atomicity (eg in Rails'
RedisCacheStore#write_multi
), so allow bypassing the CannotDistribute check.This is part of the fix for rails/rails#48938
I'm not totally decided on the best way of doing this. I'd originally tried just adding an option to the original method -
but the kwargs make it tricky - I don't think it's possible to do that and still support
redis.mapped_mset({ foo: 1}, atomic: true)
andredis.mapped_mset(foo: 1)
.Another option would be to set it as an option on the client (eg
Redis::Distributed.new(node_configs, allow_nonatomic_operations: true))
), but I decided that was a bit weird since it only really makes sense for mset and mapped_mset.So for now I went with adding extra
mset_nonatomic
&mapped_mset_nonatomic
methods, but I could definitely be persuaded otherwise.We maybe also ought to consider what the fix in Rails will look like if & when this is fixed in redis-rb. I guess if we take the approach of this PR it'd be something like:
Any opinions?