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

* mget leads to crossslot keys don't hash to the same slot #110

Merged
merged 8 commits into from
Jan 21, 2022

Conversation

rbroggi
Copy link

@rbroggi rbroggi commented Jan 19, 2022

Which problem is this PR solving?

#111
#113

Short description of the changes

if err != nil {
log.Errorf("failed to MGET keys %v: %v", w.keys, err)
return
values := make([]interface{}, len(w.keys))
Copy link
Contributor

@aziule aziule Jan 20, 2022

Choose a reason for hiding this comment

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

We should be safe to use []string here because Get(...).Result() returns a string. It would reduce the complexity and prevent from casting to interface{} and then again to string

Copy link
Author

Choose a reason for hiding this comment

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

at most []*string because we use nil to signal a bad retrieval

func (w *Watcher) getValues(ctx context.Context, ch chan<- []*change.Change) {
values, err := w.client.MGet(ctx, w.keys...).Result()
Copy link
Author

Choose a reason for hiding this comment

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

deleted keys would get nil values as you can see from the lib unit tests:

https://github.com/go-redis/redis/blob/master/commands_test.go#L1165-L1173

It means that deletion operations would not be pickedup by the service.

}
// notice: if the key is not found we default to the same behavior as if
// the key was found with an empty value string
if strCmd.Err() != nil && strCmd.Err() != redis.Nil {
Copy link
Author

Choose a reason for hiding this comment

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

we can now trigger update to "" in case the key was deleted generating consistency across pods

@rbroggi rbroggi force-pushed the redis-mget-error-crossslot branch from f2a0c4b to 65363c0 Compare January 20, 2022 16:09
@rbroggi rbroggi marked this pull request as ready for review January 20, 2022 16:10
aziule
aziule previously approved these changes Jan 21, 2022
@@ -70,20 +70,35 @@ func (w *Watcher) monitor(ctx context.Context, ch chan<- []*change.Change) {
}
}

func toPtr(s string) *string {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we inline this? it is only used in one place.

Copy link
Author

Choose a reason for hiding this comment

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

done

@mantzas mantzas merged commit 385c57d into beatlabs:master Jan 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants