How to configure redis to work with haproxy?

I am configuring HAproxy and would love using with Redis, my configuration is fairly simple:

global
    maxconn 50000

defaults
    timeout connect 10s
    timeout client 30s
    timeout server 30s
    log global
    mode http
    option httplog
    maxconn 3000

frontend redis
    log /dev/log local0 debug
    mode tcp

    bind *:7899
    default_backend redis_servers

backend redis_servers
    server r01 xxx:7899

but when I try to connect to the address with the CLI:

redis-cli -h loadbalancer.test.app -p 7899

I get this log:

Jul 18 15:19:24 lb01 haproxy[114128]: 217.XXX.XX.XXX:279XX [18/Jul/2022:15:19:24.426] redis redis/<NOSRV> -1/-1/0 0 PR 1/1/0/0/0 0/0

I verified and the redis server is working properly, if I execute the same command to connect to it, but with the ip of the machine directly, I can use it with success.

Anyone can help me understand what I am missing?

Thanks

Hello,

you get the response because backend check has failed. You should get an info message in the haproxy logs about this.

Otherwise, if your are sur your redis server is running and accepting requests check ports, firewall, … to see if anything could block requests.

Also, not sure about this but tcp instruction may be in backend section too.

Hope it can helps

Hi.

Use HAProxy in front of some Redis Cluster and everything is working pretty well stable and performant.

Configuration like…

listen Redis_Masters
     bind            0.0.0.0:6379
     mode            tcp
     maxconn         512
     fullconn        512
     timeout client  30s
     timeout server  30s
     timeout tunnel  12s

     balance leastconn

     option tcp-smart-accept
     option tcp-smart-connect
     option tcpka
     option tcplog
     option tcp-check
     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 QUIT\r\n
     tcp-check expect string +OK

     server REDIS01 xxx.xxx.xxx.101:6379 check port 6379 fall 3 rise 3 on-marked-down shutdown-sessions
     server REDIS02 xxx.xxx.xxx.102:6379 check port 6379 fall 3 rise 3 on-marked-down shutdown-sessions
     server REDIS03 xxx.xxx.xxx.103:6379 check port 6379 fall 3 rise 3 on-marked-down shutdown-sessions

Hope this can help you find the way.

Greetings,
Pedro