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

Custom key Distribution mode to prefer redis replica/slave as the backend server over the master #648

Open
Sairammp opened this issue Aug 23, 2021 · 1 comment

Comments

@Sairammp
Copy link

Hi,

I would like to know whether we can use other forms of distribution mode apart from the 3 modes listed in the doc. The requirement is, we need to redirect the Redis reads to the slave, only in case if we infer/anticipate load/issue in the master. The read requests have to be redirected to the slave well in advance the master gets overloaded. This redirection is required to save the Redis instance that can be loaded due to various reasons.

This mode will be useful not only to redirect the reads from master to slave, but it can also be from one slave to other slaves due to the higher load in the former.

-Sairam.

@TysonAndre
Copy link
Collaborator

Currently, no.

Redis sentinel support is planned for the 0.6.0 release (but not merged yet), but that is currently only designed to identify the redis master to connect to it. I'd assume connecting to the replicas is feasible, but haven't looked into how to implement it. It's something I'd planned to look into after 0.6.0 is out

Pointing twemproxy at haproxy can be used as a workaround, assuming that haproxy is listening on port 16389, the redis master is typically on port 6389, and the redis replica is typically on port 6390, an example haproxy config would be:

(by marking 6389 as the backup, haproxy will prefer 6390)

Note that this will make haproxy connect to redis and send requests every 5 seconds to determine the availability of the instances

listen redis-16389-exampleredis
  bind 127.0.0.1:16389
  mode tcp
  balance roundrobin
  option tcp-check
  tcp-check send role\r\n
  tcp-check expect rstring connected|master
  tcp-check send quit\r\n
  tcp-check expect string +OK
  timeout check 1s
  timeout connect 1s
  server 127.0.0.1 127.0.0.1:6389 check backup
  server 127.0.0.1 127.0.0.1:6390 check

@TysonAndre TysonAndre changed the title Custom key Distribution mode to choose the backend server. Custom key Distribution mode to prefer redis replica/slave as the backend server over the master Aug 29, 2021
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

No branches or pull requests

2 participants