Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -577,13 +577,12 @@ function reply_to_strings(reply) {
var i;

if (Buffer.isBuffer(reply)) {
return reply.toString();
return reply.toString();
}

if (Array.isArray(reply)) {
for (i = 0; i < reply.length; i++) {
if (reply[i] !== null && reply[i] !== undefined) {
reply[i] = reply[i].toString();
reply[i] = reply_to_strings(reply[i]);
}
}
return reply;
Expand Down Expand Up @@ -1084,6 +1083,18 @@ Multi.prototype.exec = function (callback) {
for (i = 1, il = self.queue.length; i < il; i += 1) {
reply = replies[i - 1];
args = self.queue[i];
var bufferArgs = false;
args.forEach(function(arg) {
if(Buffer.isBuffer(arg)) {
bufferArgs = true;
return false;
}
});
if (self._client.options.detect_buffers && !bufferArgs) {
// If detect_buffers option was specified, then the reply from the parser will be Buffers.
// If this command did not use Buffer arguments, then convert the reply to Strings here.
reply = reply_to_strings(reply);
}

// TODO - confusing and error-prone that hgetall is special cased in two places
if (reply && args[0].toLowerCase() === "hgetall") {
Expand Down
12 changes: 5 additions & 7 deletions lib/parser/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function small_toString(buf, start, end) {
}

ReplyParser.prototype._parseResult = function (type) {
var start, end, offset, packetHeader;
var start, end, offset, packetHeader, buffer;

if (type === 43 || type === 45) { // + or -
// up to the delimiter
Expand All @@ -58,7 +58,8 @@ ReplyParser.prototype._parseResult = function (type) {
}

if (this.options.return_buffers) {
return this._buffer.slice(start, end);
buffer = this._buffer.slice(start, end);
return buffer;
} else {
if (end - start < 65536) { // completely arbitrary
return small_toString(this._buffer, start, end);
Expand All @@ -79,10 +80,6 @@ ReplyParser.prototype._parseResult = function (type) {
throw new IncompleteReadBuffer("Wait for more data.");
}

if (this.options.return_buffers) {
return this._buffer.slice(start, end);
}

// return the coerced numeric value
return +small_toString(this._buffer, start, end);
} else if (type === 36) { // $
Expand All @@ -109,7 +106,8 @@ ReplyParser.prototype._parseResult = function (type) {
}

if (this.options.return_buffers) {
return this._buffer.slice(start, end);
buffer = this._buffer.slice(start, end);
return buffer;
} else {
return this._buffer.toString(this._encoding, start, end);
}
Expand Down