You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-09 00:22:08 +03:00
@@ -54,6 +54,11 @@ ReplyParser.prototype._parseResult = function (type) {
|
||||
throw new IncompleteReadBuffer("Wait for more data.");
|
||||
}
|
||||
|
||||
if (type === 45) {
|
||||
var result = this._buffer.toString(this._encoding, start, end);
|
||||
return new Error(result);
|
||||
}
|
||||
|
||||
if (this.options.return_buffers) {
|
||||
return this._buffer.slice(start, end);
|
||||
} else {
|
||||
@@ -76,12 +81,8 @@ 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);
|
||||
return +this._buffer.toString('ascii', start, end);
|
||||
} else if (type === 36) { // $
|
||||
// set a rewind point, as the packet could be larger than the
|
||||
// buffer in memory
|
||||
@@ -123,7 +124,7 @@ ReplyParser.prototype._parseResult = function (type) {
|
||||
throw new IncompleteReadBuffer("Wait for more data.");
|
||||
}
|
||||
|
||||
var reply = [ ];
|
||||
var reply = [];
|
||||
var ntype, i, res;
|
||||
|
||||
offset = this._offset - 1;
|
||||
@@ -152,36 +153,25 @@ ReplyParser.prototype.execute = function (buffer) {
|
||||
|
||||
while (true) {
|
||||
offset = this._offset;
|
||||
try {
|
||||
// at least 4 bytes: :1\r\n
|
||||
if (this._bytesRemaining() < 4) {
|
||||
break;
|
||||
}
|
||||
|
||||
try {
|
||||
type = this._buffer[this._offset++];
|
||||
|
||||
if (type === 43) { // +
|
||||
ret = this._parseResult(type);
|
||||
|
||||
if (ret === null) {
|
||||
break;
|
||||
}
|
||||
|
||||
this.send_reply(ret);
|
||||
} else if (type === 45) { // -
|
||||
ret = this._parseResult(type);
|
||||
|
||||
if (ret === null) {
|
||||
break;
|
||||
}
|
||||
this.send_error(new Error(ret));
|
||||
this.send_error(ret);
|
||||
} else if (type === 58) { // :
|
||||
ret = this._parseResult(type);
|
||||
|
||||
if (ret === null) {
|
||||
break;
|
||||
}
|
||||
|
||||
this.send_reply(ret);
|
||||
} else if (type === 36) { // $
|
||||
ret = this._parseResult(type);
|
||||
@@ -219,9 +209,6 @@ ReplyParser.prototype.execute = function (buffer) {
|
||||
};
|
||||
|
||||
ReplyParser.prototype.append = function (newBuffer) {
|
||||
if (!newBuffer) {
|
||||
return;
|
||||
}
|
||||
|
||||
// first run
|
||||
if (this._buffer === null) {
|
||||
@@ -238,27 +225,13 @@ ReplyParser.prototype.append = function (newBuffer) {
|
||||
return;
|
||||
}
|
||||
|
||||
// very large packet
|
||||
// check for concat, if we have it, use it
|
||||
if (Buffer.concat !== undefined) {
|
||||
this._buffer = Buffer.concat([this._buffer.slice(this._offset), newBuffer]);
|
||||
} else {
|
||||
var remaining = this._bytesRemaining(),
|
||||
newLength = remaining + newBuffer.length,
|
||||
tmpBuffer = new Buffer(newLength);
|
||||
|
||||
this._buffer.copy(tmpBuffer, 0, this._offset);
|
||||
newBuffer.copy(tmpBuffer, remaining, 0);
|
||||
|
||||
this._buffer = tmpBuffer;
|
||||
}
|
||||
|
||||
this._offset = 0;
|
||||
};
|
||||
|
||||
ReplyParser.prototype.parseHeader = function () {
|
||||
var end = this._packetEndOffset(),
|
||||
value = small_toString(this._buffer, this._offset, end - 1);
|
||||
value = this._buffer.toString('ascii', this._offset, end - 1);
|
||||
|
||||
this._offset = end + 1;
|
||||
|
||||
@@ -270,10 +243,6 @@ ReplyParser.prototype._packetEndOffset = function () {
|
||||
|
||||
while (this._buffer[offset] !== 0x0d && this._buffer[offset + 1] !== 0x0a) {
|
||||
offset++;
|
||||
|
||||
if (offset >= this._buffer.length) {
|
||||
throw new IncompleteReadBuffer("didn't see LF after NL reading multi bulk count (" + offset + " => " + this._buffer.length + ", " + this._offset + ")");
|
||||
}
|
||||
}
|
||||
|
||||
offset++;
|
||||
|
Reference in New Issue
Block a user