|
|
@ -4,37 +4,32 @@ var hiredis = require('hiredis'); |
|
|
|
|
|
|
|
function HiredisReplyParser(return_buffers) { |
|
|
|
this.name = exports.name; |
|
|
|
this.return_buffers = return_buffers; |
|
|
|
this.reset(); |
|
|
|
} |
|
|
|
|
|
|
|
HiredisReplyParser.prototype.reset = function () { |
|
|
|
this.reader = new hiredis.Reader({ |
|
|
|
return_buffers: this.return_buffers || false |
|
|
|
return_buffers: return_buffers |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
HiredisReplyParser.prototype.return_data = function () { |
|
|
|
try { |
|
|
|
return this.reader.get(); |
|
|
|
} catch (err) { |
|
|
|
// Protocol errors land here
|
|
|
|
this.send_error(err); |
|
|
|
return void 0; |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
HiredisReplyParser.prototype.execute = function (data) { |
|
|
|
var reply; |
|
|
|
this.reader.feed(data); |
|
|
|
while (true) { |
|
|
|
try { |
|
|
|
reply = this.reader.get(); |
|
|
|
} catch (err) { |
|
|
|
// Protocol errors land here
|
|
|
|
this.send_error(err); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
if (reply === undefined) { |
|
|
|
break; |
|
|
|
} |
|
|
|
var reply = this.return_data(); |
|
|
|
|
|
|
|
if (reply && reply.constructor === Error) { |
|
|
|
while (reply !== undefined) { |
|
|
|
if (reply && reply.name === 'Error') { |
|
|
|
this.send_error(reply); |
|
|
|
} else { |
|
|
|
this.send_reply(reply); |
|
|
|
} |
|
|
|
reply = this.return_data(); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|