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

Allow user specified host in connection with sentinel #620

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

Conversation

koterevma
Copy link

Hi! It's my first time contributing to an open source project, so feel free to point out if i made something wrong

What is the problem?

I am trying to use redis as an external cache for latency-critical application that is scaled on three different physical servers

So for each application instance situation looks like this:

We have one redis instance that is available locally and two redis instances that are available but will cost a few net hops to reach (we want to avoid that at all costs). Preferred behavior is to always send readonly operations to local redis instance if possible, and if it is not alive, then we must go to any other available instance

The main issue is net latency with Redis client created with Sentinel and configured to read from Role::SLAVE because it chooses random host, but I want to specify preferred one

Suggestion

Allow user to specify host+port in ConnectionOptions and if it is suitable according to configuration, then use it

If user leaves host unspecified the behavior of connection pool with sentinel will be the same - randomly choose host from available replicas

Example

Before changes:

// Assume that we are running on server-1 and redis-instance-1 has the least network delay
connection_opts.host = "redis-instance-1";
connection_opts.port = 6379;
// While creating ConnectionPool we silently ignore host specified by user earlier
auto slave = Redis(sentinel, "master_name", Role::SLAVE, connection_opts, pool_opts);
slave.get("key");  // Possible net hops, random

After changes

// Assume that we are running on server-1 and redis-instance-1 has the least network delay 
connection_opts.host = "redis-instance-1";
connection_opts.port = 6379;
// Not ignoring host specified by user
auto slave = Redis(sentinel, "master_name", Role::SLAVE, connection_opts, pool_opts);
slave.get("key");  // Guaranteed low latency if redis-instance-1 is alive and is has role "slave"
// The same behavior as before changes: 
connection_opts.host = "";  // Set to empty string or leave unspecified
auto slave = Redis(sentinel, "master_name", Role::SLAVE, connection_opts, pool_opts);
slave.get("key");  // Connect to randomly selected replica

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.

1 participant