You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
Update some comments.
This commit is contained in:
25
index.js
25
index.js
@@ -18,10 +18,13 @@ function RedisReplyParser() {
|
|||||||
sys.inherits(RedisReplyParser, events.EventEmitter);
|
sys.inherits(RedisReplyParser, events.EventEmitter);
|
||||||
|
|
||||||
RedisReplyParser.prototype.execute = function (incoming_buf) {
|
RedisReplyParser.prototype.execute = function (incoming_buf) {
|
||||||
var pos = 0;
|
var pos = 0, state_times = {};
|
||||||
|
//, start_execute = new Date(), start_switch, end_switch, old_state;
|
||||||
|
//start_switch = new Date();
|
||||||
|
|
||||||
while (pos < incoming_buf.length) {
|
while (pos < incoming_buf.length) {
|
||||||
// console.log("execute " + this.state + " " + pos + " " + String.fromCharCode(incoming_buf[pos]));
|
old_state = this.state;
|
||||||
|
|
||||||
switch (this.state) {
|
switch (this.state) {
|
||||||
case "type":
|
case "type":
|
||||||
this.type = incoming_buf[pos];
|
this.type = incoming_buf[pos];
|
||||||
@@ -65,7 +68,7 @@ RedisReplyParser.prototype.execute = function (incoming_buf) {
|
|||||||
break;
|
break;
|
||||||
case "error line":
|
case "error line":
|
||||||
if (incoming_buf[pos] === 13) {
|
if (incoming_buf[pos] === 13) {
|
||||||
this.send_error(this.return_buffer.toString("utf8", 0, this.return_buffer.end));
|
this.send_error(this.return_buffer.toString("ascii", 0, this.return_buffer.end));
|
||||||
this.state = "final lf";
|
this.state = "final lf";
|
||||||
} else {
|
} else {
|
||||||
this.return_buffer[this.return_buffer.end] = incoming_buf[pos];
|
this.return_buffer[this.return_buffer.end] = incoming_buf[pos];
|
||||||
@@ -95,7 +98,7 @@ RedisReplyParser.prototype.execute = function (incoming_buf) {
|
|||||||
break;
|
break;
|
||||||
case "multi bulk count lf":
|
case "multi bulk count lf":
|
||||||
if (incoming_buf[pos] === 10) { // \n
|
if (incoming_buf[pos] === 10) { // \n
|
||||||
this.multi_bulk_length = parseInt(this.tmp_buffer.toString("utf8", 0, this.tmp_buffer.end), 10);
|
this.multi_bulk_length = parseInt(this.tmp_buffer.toString("ascii", 0, this.tmp_buffer.end), 10);
|
||||||
this.multi_bulk_replies = [];
|
this.multi_bulk_replies = [];
|
||||||
this.state = "type";
|
this.state = "type";
|
||||||
} else {
|
} else {
|
||||||
@@ -116,7 +119,7 @@ RedisReplyParser.prototype.execute = function (incoming_buf) {
|
|||||||
break;
|
break;
|
||||||
case "bulk lf":
|
case "bulk lf":
|
||||||
if (incoming_buf[pos] === 10) { // \n
|
if (incoming_buf[pos] === 10) { // \n
|
||||||
this.bulk_length = parseInt(this.tmp_buffer.toString("utf8", 0, this.tmp_buffer.end), 10);
|
this.bulk_length = parseInt(this.tmp_buffer.toString("ascii", 0, this.tmp_buffer.end), 10);
|
||||||
if (this.bulk_length === -1) {
|
if (this.bulk_length === -1) {
|
||||||
this.send_reply(null);
|
this.send_reply(null);
|
||||||
this.state = "type";
|
this.state = "type";
|
||||||
@@ -139,6 +142,8 @@ RedisReplyParser.prototype.execute = function (incoming_buf) {
|
|||||||
this.return_buffer[this.return_buffer.end] = incoming_buf[pos];
|
this.return_buffer[this.return_buffer.end] = incoming_buf[pos];
|
||||||
this.return_buffer.end += 1;
|
this.return_buffer.end += 1;
|
||||||
pos += 1;
|
pos += 1;
|
||||||
|
// TODO - should be faster to use Bufer.copy() here, especially if the response is large.
|
||||||
|
// However, when the response is small, Buffer.copy() seems a lot slower. Computers are hard.
|
||||||
if (this.return_buffer.end === this.bulk_length) {
|
if (this.return_buffer.end === this.bulk_length) {
|
||||||
// this ugilness could go away if we gave the user a volatile buffer, but that seems dangerous
|
// this ugilness could go away if we gave the user a volatile buffer, but that seems dangerous
|
||||||
var bd_tmp = new Buffer(this.bulk_length);
|
var bd_tmp = new Buffer(this.bulk_length);
|
||||||
@@ -170,7 +175,17 @@ RedisReplyParser.prototype.execute = function (incoming_buf) {
|
|||||||
default:
|
default:
|
||||||
throw new Error("invalid state " + this.state);
|
throw new Error("invalid state " + this.state);
|
||||||
}
|
}
|
||||||
|
// end_switch = new Date();
|
||||||
|
// if (state_times[old_state] === undefined) {
|
||||||
|
// state_times[old_state] = 0;
|
||||||
|
// }
|
||||||
|
// state_times[old_state] += (end_switch - start_switch);
|
||||||
|
// start_switch = end_switch;
|
||||||
}
|
}
|
||||||
|
// console.log("execute ran for " + (Date.now() - start_execute) + " ms, on " + incoming_buf.length + " Bytes. ");
|
||||||
|
// Object.keys(state_times).forEach(function (state) {
|
||||||
|
// console.log(" " + state + ": " + state_times[state]);
|
||||||
|
// });
|
||||||
};
|
};
|
||||||
|
|
||||||
RedisReplyParser.prototype.send_error = function (reply) {
|
RedisReplyParser.prototype.send_error = function (reply) {
|
||||||
|
Reference in New Issue
Block a user