HAproxy for redis slaves

We are using the node_redis client to access redis for the time being. I need to use HAProxy before redis slaves, which in my case is 3 ns. I installed HAProxy and configured it to balance redis balancing. But when I tried to create a connection with the node_redis client with HAProxy, I could not create a connection and received an 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) 
+7
source share
1 answer

Posting a haproxy configuration would help ...

The most likely explanation is that haproxy is not configured to handle general 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 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 exact same 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 this, simply modify the haproxy configuration to provide common TCP mode:

  mode http to be changed into: mode tcp 

... and now it works great.

+19
source

All Articles