HTTP status codes for Redis Sentinel when using TLS.
To offer high availability when using HAProxy and Redis + Sentinel are configured to use TLS.
When not using TLS, HAProxy can be configured like this to find the current master:
backend redis
mode tcp
balance first
timeout queue 5s
default-server check inter 1s fall 2 rise 2 maxconn 500
option tcp-check
tcp-check connect
tcp-check send AUTH\ secret\r\n
tcp-check expect string +OK
tcp-check send PING\r\n
tcp-check expect string +PONG
tcp-check send info\ replication\r\n
tcp-check expect string role:master
tcp-check send info\ server\r\n
tcp-check expect rstring uptime_in_seconds:\d{2,}
tcp-check send QUIT\r\n
tcp-check expect string +OK
server redis1 10.0.1.11:6379
server redis2 10.0.1.12:6379
server redis3 10.0.1.13:6379
This works very good, but if Redis is configured to use TLS, the
option tcp-check
doesn't work since it doesn't support TLS.
httpredis
is a web service that connects to Redis using TLS, when requesting
info replication
if role is role:master
the service will return the HTTP
status code 200
.
The HAProxy
configuration can be:
backend redis
mode tcp
option httpchk
default-server check port 36379