1

I'm facing an issue while connecting to Redis server via HAProxy using Jedis as a redis client. Everything works fine when Redis server is directly connected to but, the same is not working via HAProxy. Both HAProxy and Redis services are running on their specific ports, HAProxy on port 80 & Redis server on 6379. We are running this setup on EC2 instances and all the necessary ports are open.

HAProxy Configuration is

frontend redis-in
bind *:80
default_backend redis-server

backend redis-server
    stats   enable
    server redis-server1 x.x.x.x:6379 check inter 1000 fall 3 rise 2
    server redis-server2 x.x.x.x:6379 check inter 1000 fall 3 rise 2

Jedis Clinet code is:

 try {
    Jedis jedis = new Jedis(hostname, port);
    jedis.set("key", "Redis-Test-Value");
    System.out.println("value from redis node is: " + jedis.get("key"));
} catch (Exception e) {
    System.out.println("exception is " + e);
}

Exception message that gets thrown is - redis.clients.jedis.exceptions.JedisConnectionException: Unknown reply: H

Can someone point out what am I missing and point to the right direction?

1 Answers1

0

You've set stats option in your backend, seems that due to that you get an HTTP response (probably a 502 error), of which the first character is seen in the jedis output. So remove that and create a separate listen directive to serve stats, like so:

listen stats # Define a listen section called "stats"
  bind :9988 # Listen on localhost:9000
  mode http
  stats enable  # Enable stats page
  stats hide-version  # Hide HAProxy version
  stats uri /stats  # Stats URI
Gothrek
  • 512
  • 2
  • 7