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?

3
  • Is this the complete configuration of haproxy? – Khaled Feb 22 '18 at 8:44
  • yes this is my frontend and backend configuration. I have global and default configuration section of HAProxy as well. – Sandeep Singh Feb 23 '18 at 12:41
  • Can you post the complete config? – Khaled Feb 24 '18 at 8:29
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
1
  • i added mode tcp in my backend and it worked. – Sandeep Singh Mar 6 '18 at 6:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.