You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-07 13:22:56 +03:00
Whitespace and other JSHint changes.
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
/*global Buffer require exports console setTimeout */
|
||||
|
||||
var events = require("events"),
|
||||
util = require("../util"),
|
||||
hiredis = require("hiredis");
|
||||
@@ -29,13 +27,15 @@ HiredisReplyParser.prototype.execute = function (data) {
|
||||
this.reader.feed(data);
|
||||
while (true) {
|
||||
try {
|
||||
reply = this.reader.get();
|
||||
reply = this.reader.get();
|
||||
} catch (err) {
|
||||
this.emit("error", err);
|
||||
break;
|
||||
this.emit("error", err);
|
||||
break;
|
||||
}
|
||||
|
||||
if (reply === undefined) break;
|
||||
if (reply === undefined) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (reply && reply.constructor === Error) {
|
||||
this.emit("reply error", reply);
|
||||
|
@@ -1,28 +1,28 @@
|
||||
var events = require("events"),
|
||||
util = require('../util');
|
||||
util = require("../util");
|
||||
|
||||
function Packet (type, size) {
|
||||
function Packet(type, size) {
|
||||
this.type = type;
|
||||
this.size = +size;
|
||||
}
|
||||
|
||||
exports.name = 'faster';
|
||||
exports.name = "faster";
|
||||
exports.debug_mode = false;
|
||||
|
||||
function FasterReplyParser (options) {
|
||||
function ReplyParser(options) {
|
||||
this.name = exports.name;
|
||||
this.options = options || { };
|
||||
|
||||
this._buffer = null;
|
||||
this._offset = 0;
|
||||
this._encoding = 'utf-8';
|
||||
this._encoding = "utf-8";
|
||||
this._debug_mode = options.debug_mode;
|
||||
this._reply_type = null;
|
||||
}
|
||||
|
||||
util.inherits(FasterReplyParser, events.EventEmitter);
|
||||
util.inherits(ReplyParser, events.EventEmitter);
|
||||
|
||||
exports.Parser = FasterReplyParser;
|
||||
exports.Parser = ReplyParser;
|
||||
|
||||
// Buffer.toString() is quite slow for small strings
|
||||
function small_toString(buf, start, end) {
|
||||
@@ -35,7 +35,7 @@ function small_toString(buf, start, end) {
|
||||
return tmp;
|
||||
}
|
||||
|
||||
FasterReplyParser.prototype._parseResult = function (type) {
|
||||
ReplyParser.prototype._parseResult = function (type) {
|
||||
var start, end, offset, packetHeader;
|
||||
|
||||
if (type === 43 || type === 45) { // + or -
|
||||
@@ -77,7 +77,6 @@ FasterReplyParser.prototype._parseResult = function (type) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
end = this._offset + packetHeader.size;
|
||||
start = this._offset;
|
||||
|
||||
@@ -117,7 +116,7 @@ FasterReplyParser.prototype._parseResult = function (type) {
|
||||
ntype = this._buffer[this._offset++];
|
||||
|
||||
if (this._offset === this._buffer.length) {
|
||||
throw new Error('too far');
|
||||
throw new Error("too far");
|
||||
}
|
||||
reply.push(this._parseResult(ntype));
|
||||
}
|
||||
@@ -126,7 +125,7 @@ FasterReplyParser.prototype._parseResult = function (type) {
|
||||
}
|
||||
};
|
||||
|
||||
FasterReplyParser.prototype.execute = function (buffer) {
|
||||
ReplyParser.prototype.execute = function (buffer) {
|
||||
this.append(buffer);
|
||||
|
||||
var type, ret, offset;
|
||||
@@ -140,13 +139,12 @@ FasterReplyParser.prototype.execute = function (buffer) {
|
||||
}
|
||||
|
||||
type = this._buffer[this._offset++];
|
||||
|
||||
|
||||
|
||||
if (type === 43) { // +
|
||||
ret = this._parseResult(type);
|
||||
|
||||
if (ret === null) {
|
||||
break;
|
||||
break;
|
||||
}
|
||||
|
||||
this.send_reply(ret);
|
||||
@@ -154,7 +152,7 @@ FasterReplyParser.prototype.execute = function (buffer) {
|
||||
ret = this._parseResult(type);
|
||||
|
||||
if (ret === null) {
|
||||
break;
|
||||
break;
|
||||
}
|
||||
|
||||
this.send_error(ret);
|
||||
@@ -162,7 +160,7 @@ FasterReplyParser.prototype.execute = function (buffer) {
|
||||
ret = this._parseResult(type);
|
||||
|
||||
if (ret === null) {
|
||||
break;
|
||||
break;
|
||||
}
|
||||
|
||||
this.send_reply(+ret);
|
||||
@@ -170,7 +168,7 @@ FasterReplyParser.prototype.execute = function (buffer) {
|
||||
ret = this._parseResult(type);
|
||||
|
||||
if (ret === null) {
|
||||
break;
|
||||
break;
|
||||
}
|
||||
|
||||
this.send_reply(ret);
|
||||
@@ -188,16 +186,16 @@ FasterReplyParser.prototype.execute = function (buffer) {
|
||||
|
||||
this.send_reply(ret);
|
||||
}
|
||||
} catch(err) {
|
||||
// catch the error (not enough data), rewind, and wait
|
||||
// for the next packet to appear
|
||||
this._offset = offset;
|
||||
break;
|
||||
} catch (err) {
|
||||
// catch the error (not enough data), rewind, and wait
|
||||
// for the next packet to appear
|
||||
this._offset = offset;
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
FasterReplyParser.prototype.append = function(newBuffer) {
|
||||
ReplyParser.prototype.append = function (newBuffer) {
|
||||
if (!newBuffer) {
|
||||
return;
|
||||
}
|
||||
@@ -235,42 +233,42 @@ FasterReplyParser.prototype.append = function(newBuffer) {
|
||||
this._offset = 0;
|
||||
};
|
||||
|
||||
FasterReplyParser.prototype.parseHeader = function () {
|
||||
ReplyParser.prototype.parseHeader = function () {
|
||||
var end = this._packetEndOffset(),
|
||||
value = small_toString(this._buffer, this._offset, end - 1);
|
||||
value = small_toString(this._buffer, this._offset, end - 1);
|
||||
|
||||
this._offset = end + 1;
|
||||
|
||||
return value;
|
||||
};
|
||||
|
||||
FasterReplyParser.prototype._packetEndOffset = function () {
|
||||
ReplyParser.prototype._packetEndOffset = function () {
|
||||
var offset = this._offset;
|
||||
|
||||
while (this._buffer[offset] !== 0x0d && this._buffer[offset + 1] !== 0x0a) {
|
||||
offset++;
|
||||
|
||||
|
||||
if (offset >= this._buffer.length) {
|
||||
throw new Error("didn't see LF after NL reading multi bulk count (" + offset + " => " + this._buffer.length + ", " + this._offset + ")");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
offset++;
|
||||
return offset;
|
||||
};
|
||||
|
||||
FasterReplyParser.prototype._bytesRemaining = function() {
|
||||
ReplyParser.prototype._bytesRemaining = function () {
|
||||
return (this._buffer.length - this._offset) < 0 ? 0 : (this._buffer.length - this._offset);
|
||||
};
|
||||
|
||||
FasterReplyParser.prototype.parser_error = function (message) {
|
||||
ReplyParser.prototype.parser_error = function (message) {
|
||||
this.emit("error", message);
|
||||
};
|
||||
|
||||
FasterReplyParser.prototype.send_error = function (reply) {
|
||||
ReplyParser.prototype.send_error = function (reply) {
|
||||
this.emit("reply error", reply);
|
||||
};
|
||||
|
||||
FasterReplyParser.prototype.send_reply = function (reply) {
|
||||
ReplyParser.prototype.send_reply = function (reply) {
|
||||
this.emit("reply", reply);
|
||||
};
|
@@ -1,5 +1,3 @@
|
||||
var to_array = require("./to_array");
|
||||
|
||||
// Queue class adapted from Tim Caswell's pattern library
|
||||
// http://github.com/creationix/pattern/blob/master/lib/pattern/queue.js
|
||||
|
||||
@@ -49,13 +47,13 @@ Queue.prototype.getLength = function () {
|
||||
return this.head.length - this.offset + this.tail.length;
|
||||
};
|
||||
|
||||
Object.defineProperty(Queue.prototype, 'length', {
|
||||
Object.defineProperty(Queue.prototype, "length", {
|
||||
get: function () {
|
||||
return this.getLength();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
if(typeof module !== 'undefined' && module.exports) {
|
||||
module.exports = Queue;
|
||||
if (typeof module !== "undefined" && module.exports) {
|
||||
module.exports = Queue;
|
||||
}
|
||||
|
Reference in New Issue
Block a user