You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
@@ -1,6 +1,13 @@
|
||||
Changelog
|
||||
=========
|
||||
|
||||
## v.2.3.1 - xx Nov, 2015
|
||||
|
||||
Bugfixes
|
||||
|
||||
- Fixed js parser handling big values very slow ([@BridgeAR](https://github.com/BridgeAR))
|
||||
- The speed is up to ~500% faster than before but still up to ~50% slower than the hiredis parser.
|
||||
|
||||
## v.2.3.0 - 30 Oct, 2015
|
||||
|
||||
Features
|
||||
|
2
index.js
2
index.js
@@ -733,7 +733,7 @@ RedisClient.prototype.send_command = function (command, args, callback) {
|
||||
buffer_args = true;
|
||||
} else if (typeof args[i] !== 'string') {
|
||||
args[i] = String(args[i]);
|
||||
// 30000 seemed to be a good value to switch to buffers after testing this with and checking the pros and cons
|
||||
// 30000 seemed to be a good value to switch to buffers after testing and checking the pros and cons
|
||||
} else if (args[i].length > 30000) {
|
||||
big_data = true;
|
||||
args[i] = new Buffer(args[i]);
|
||||
|
@@ -6,6 +6,7 @@ function JavascriptReplyParser() {
|
||||
this.name = exports.name;
|
||||
this._buffer = new Buffer(0);
|
||||
this._offset = 0;
|
||||
this._buffers = [];
|
||||
}
|
||||
|
||||
function IncompleteReadBuffer(message) {
|
||||
@@ -66,7 +67,7 @@ JavascriptReplyParser.prototype._parseResult = function (type) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (packetHeader > this._bytesRemaining()) {
|
||||
if (packetHeader > this._buffer.length - this._offset) {
|
||||
this._offset = offset - 1;
|
||||
throw new IncompleteReadBuffer('Wait for more data.');
|
||||
}
|
||||
@@ -93,14 +94,37 @@ JavascriptReplyParser.prototype._parseResult = function (type) {
|
||||
};
|
||||
|
||||
JavascriptReplyParser.prototype.execute = function (buffer) {
|
||||
this.append(buffer);
|
||||
var i = buffer.length - 1;
|
||||
|
||||
var type, offset;
|
||||
while (buffer[i] !== 0x0a) {
|
||||
i--;
|
||||
if (i < 1) {
|
||||
this._buffers.push(buffer);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (this._buffers.length !== 0) {
|
||||
this._buffers.unshift(this._offset === 0 ? this._buffer : this._buffer.slice(this._offset));
|
||||
this._buffers.push(buffer);
|
||||
this._buffer = Buffer.concat(this._buffers);
|
||||
this._buffers = [];
|
||||
} else if (this._offset >= this._buffer.length) {
|
||||
this._buffer = buffer;
|
||||
} else {
|
||||
this._buffer = Buffer.concat([this._buffer.slice(this._offset), buffer]);
|
||||
}
|
||||
this._offset = 0;
|
||||
this.run();
|
||||
};
|
||||
|
||||
JavascriptReplyParser.prototype.run = function (buffer) {
|
||||
var type, offset = this._offset;
|
||||
|
||||
while (true) {
|
||||
offset = this._offset;
|
||||
// at least 4 bytes: :1\r\n
|
||||
if (this._bytesRemaining() < 4) {
|
||||
if (this._buffer.length - this._offset < 4) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -130,24 +154,11 @@ JavascriptReplyParser.prototype.execute = function (buffer) {
|
||||
}
|
||||
};
|
||||
|
||||
JavascriptReplyParser.prototype.append = function (newBuffer) {
|
||||
|
||||
// out of data
|
||||
if (this._offset >= this._buffer.length) {
|
||||
this._buffer = newBuffer;
|
||||
this._offset = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
this._buffer = Buffer.concat([this._buffer.slice(this._offset), newBuffer]);
|
||||
this._offset = 0;
|
||||
};
|
||||
|
||||
JavascriptReplyParser.prototype.parseHeader = function () {
|
||||
var end = this._packetEndOffset() + 1,
|
||||
value = this._buffer.toString('ascii', this._offset, end - 1) | 0;
|
||||
var end = this._packetEndOffset(),
|
||||
value = this._buffer.toString('ascii', this._offset, end) | 0;
|
||||
|
||||
this._offset = end + 1;
|
||||
this._offset = end + 2;
|
||||
|
||||
return value;
|
||||
};
|
||||
@@ -167,9 +178,5 @@ JavascriptReplyParser.prototype._packetEndOffset = function () {
|
||||
return offset;
|
||||
};
|
||||
|
||||
JavascriptReplyParser.prototype._bytesRemaining = function () {
|
||||
return (this._buffer.length - this._offset) < 0 ? 0 : (this._buffer.length - this._offset);
|
||||
};
|
||||
|
||||
exports.Parser = JavascriptReplyParser;
|
||||
exports.name = 'javascript';
|
||||
|
Reference in New Issue
Block a user