Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HAproxy for redis slaves

We are using node_redis client to access the redis at present. I need to use HAProxy in front of redis slaves which in my case is 3 nos. I installed the HAProxy and configured it to load balance the redis slaves. But when I tried to create connection from the node_redis client to the HAProxy I was not able to create the connection and was getting a error

   Error: Redis reply parser error: Error: Protocol error, got "H" as reply type byte
at HiredisReplyParser.execute (/home/user1/doosra/node-exp/node_modules/redis/lib/parser/hiredis.js:32:31)
at RedisClient.on_data (/home/user1/doosra/node-exp/node_modules/redis/index.js:440:27)
at Socket.<anonymous> (/home/user1/doosra/node-exp/node_modules/redis/index.js:70:14)
at Socket.emit (events.js:67:17)
at TCP.onread (net.js:347:14)
like image 538
user1386776 Avatar asked May 10 '12 10:05

user1386776


People also ask

What is Redis HAProxy?

HAProxy - A front-end TCP load balancer for proxying incoming client application connections on port 6378 to backend Redis master server.

How create Redis Sentinel?

Launch Sentinel conf files, you must restart the Redis service for the changes to take effect, and then you can launch Redis in Sentinel mode. To restart the Redis service, run this command: sudo service redis restart . To start Redis in Sentinel mode, run redis-server /etc/redis/sentinel. conf –sentinel .

What is Redis Sentinel?

Redis Sentinel is a dedicated process to automate and simplify the Redis replication failover and switchover. Without Sentinel, you could also manage your Redis replication manually, by using the SLAVEOF or REPLICAOF command.

How do I connect to Redis Sentinel?

Commands. Use “redis-cli” with port 26379 to connect to sentinel. Note: you always want to tail the /var/log/sentinel/sentinel. log on all sentinels to see the cluster interaction.


1 Answers

Posting the haproxy configuration would have helped ...

The most likely explanation is haproxy is not configured to process generic TCP traffic but HTTP traffic.

Example:

With the following configuration:

global
    daemon
    maxconn 256

defaults
    mode http
    timeout connect 5000ms
    timeout client 50000ms
    timeout server 50000ms

frontend redis
    bind *:1521
    default_backend servers

backend servers
    server R1 127.0.0.1:6379 maxconn 1000

and the following node.js script:

var redis = require('redis')
var redis_client = redis.createClient(1521, 'localhost');
redis_client.get( 'key', function(e,o) {
    console.log("return "+e+o);
});

... we get the same exact error:

Error: Redis reply parser error: Error: Protocol error, got "H" as reply type byte

It is expected, because the Redis protocol parser does not understand HTTP. To fix it, just alter the haproxy configuration to enforce a generic TCP mode:

    mode http

to be changed into:

    mode tcp

... and now it works fine.

like image 199
Didier Spezia Avatar answered Oct 28 '22 23:10

Didier Spezia