-
Notifications
You must be signed in to change notification settings - Fork 2.4k
ReadFromAny (master+replica) without cluster mode (Master-Replica setup) #2995
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
@singh-bhawani thank you for the contribution! Would you please add tests to cover the code you are introducing? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for read-only commands to be routed to both master and replica nodes in a master-replica setup.
- Introduces a new boolean flag "ReadFromAny" to the FailoverOptions struct.
- Updates the masterReplicaDialer to select a random address when reading from any node.
- Implements a new method RandomAddr that aggregates replica addresses and the master address.
} | ||
} | ||
|
||
masterAdd, _ := c.MasterAddr(ctx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider handling the error returned by c.MasterAddr(ctx) to ensure that the master address is valid before appending it to the addresses pool.
masterAdd, _ := c.MasterAddr(ctx) | |
masterAdd, err := c.MasterAddr(ctx) | |
if err != nil { | |
return "", err | |
} |
Copilot uses AI. Check for mistakes.
Right now, with go-redis, we can't read from both the Master and its Replica without being in cluster mode. Also, when we use "ReplicaOnly", it randomly chooses Replica to read. This causes a problem because caching is mainly used for read heavy usecase, which means the Master only used for write throughput and it's resource are underutilized.
To solve this, I added "ReadFromAny" to "FailoverOptions". This means that read-only commands will come from both Replicas as well as Master. This way, we can make better use of the caching resource.