Skip to content

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

singh-bhawani
Copy link

@singh-bhawani singh-bhawani commented May 13, 2024

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.

@ndyakov ndyakov requested review from Copilot and ndyakov March 4, 2025 14:25
Copy link
Contributor

@Copilot Copilot AI left a 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.

@ndyakov
Copy link
Member

ndyakov commented Apr 16, 2025

@singh-bhawani thank you for the contribution! Would you please add tests to cover the code you are introducing?

Copy link
Member

@ndyakov ndyakov left a comment

Choose a reason for hiding this comment

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

Please add tests.

Copy link
Contributor

@Copilot Copilot AI left a 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)
Copy link
Preview

Copilot AI Apr 29, 2025

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.

Suggested change
masterAdd, _ := c.MasterAddr(ctx)
masterAdd, err := c.MasterAddr(ctx)
if err != nil {
return "", err
}

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants