2012-05-10 29 views
7

Hiện tại chúng tôi đang sử dụng trình khách node_redis để truy cập vào redis. Tôi cần phải sử dụng HAProxy trước những nô lệ đỏ mà trong trường hợp của tôi là 3 nos. Tôi đã cài đặt HAProxy và cấu hình nó để cân bằng tải các nô lệ redis. Nhưng khi tôi đã cố gắng để tạo kết nối từ client node_redis đến HAProxy Tôi đã không thể tạo ra các kết nối và đã nhận được một lỗiHAproxy cho redis slaves

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) 
+1

Liên kết tới danh sách gửi thư về câu hỏi chính xác này - https://groups.google.com/d/msg/redis-db/2yELzDSz1y4/hIeFhh7-WIUJ –

Trả lời

19

gửi bài cấu hình haproxy sẽ giúp ...

Nhất có thể giải thích là haproxy không được cấu hình để xử lý lưu lượng TCP chung nhưng lưu lượng HTTP.

Ví dụ:

Với cấu hình như sau:

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 

và kịch bản Node.js sau:

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

... chúng tôi nhận được lỗi chính xác giống nhau:

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

Dự kiến, vì trình phân tích cú pháp giao thức Redis không hiểu HTTP. Để khắc phục nó, chỉ cần thay đổi cấu hình haproxy để thực thi một chế độ TCP generic:

mode http 

to be changed into: 

    mode tcp 

... và bây giờ nó hoạt động tốt.