You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
Whitespace and other JSHint changes.
This commit is contained in:
32
index.js
32
index.js
@@ -130,8 +130,7 @@ RedisClient.prototype.flush_and_error = function (message) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
RedisClient.prototype.on_error = function (msg) {
|
RedisClient.prototype.on_error = function (msg) {
|
||||||
var message = "Redis connection to " + this.host + ":" + this.port + " failed - " + msg,
|
var message = "Redis connection to " + this.host + ":" + this.port + " failed - " + msg;
|
||||||
self = this, command_obj;
|
|
||||||
|
|
||||||
if (this.closing) {
|
if (this.closing) {
|
||||||
return;
|
return;
|
||||||
@@ -198,7 +197,6 @@ RedisClient.prototype.on_connect = function () {
|
|||||||
if (exports.debug_mode) {
|
if (exports.debug_mode) {
|
||||||
console.log("Stream connected " + this.host + ":" + this.port + " id " + this.connection_id);
|
console.log("Stream connected " + this.host + ":" + this.port + " id " + this.connection_id);
|
||||||
}
|
}
|
||||||
var self = this;
|
|
||||||
|
|
||||||
this.connected = true;
|
this.connected = true;
|
||||||
this.ready = false;
|
this.ready = false;
|
||||||
@@ -289,12 +287,12 @@ RedisClient.prototype.on_ready = function () {
|
|||||||
if (this.pub_sub_mode === true) {
|
if (this.pub_sub_mode === true) {
|
||||||
// only emit "ready" when all subscriptions were made again
|
// only emit "ready" when all subscriptions were made again
|
||||||
var callback_count = 0;
|
var callback_count = 0;
|
||||||
var callback = function() {
|
var callback = function () {
|
||||||
callback_count--;
|
callback_count--;
|
||||||
if (callback_count == 0) {
|
if (callback_count === 0) {
|
||||||
self.emit("ready");
|
self.emit("ready");
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
Object.keys(this.subscription_set).forEach(function (key) {
|
Object.keys(this.subscription_set).forEach(function (key) {
|
||||||
var parts = key.split(" ");
|
var parts = key.split(" ");
|
||||||
if (exports.debug_mode) {
|
if (exports.debug_mode) {
|
||||||
@@ -389,7 +387,7 @@ RedisClient.prototype.send_offline_queue = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
RedisClient.prototype.connection_gone = function (why) {
|
RedisClient.prototype.connection_gone = function (why) {
|
||||||
var self = this, message;
|
var self = this;
|
||||||
|
|
||||||
// If a retry is already in progress, just let that happen
|
// If a retry is already in progress, just let that happen
|
||||||
if (this.retry_timer) {
|
if (this.retry_timer) {
|
||||||
@@ -562,7 +560,7 @@ function reply_to_strings(reply) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
RedisClient.prototype.return_reply = function (reply) {
|
RedisClient.prototype.return_reply = function (reply) {
|
||||||
var command_obj, obj, i, len, type, timestamp, argindex, args, queue_len;
|
var command_obj, len, type, timestamp, argindex, args, queue_len;
|
||||||
|
|
||||||
command_obj = this.command_queue.shift(),
|
command_obj = this.command_queue.shift(),
|
||||||
queue_len = this.command_queue.getLength();
|
queue_len = this.command_queue.getLength();
|
||||||
@@ -646,7 +644,7 @@ function Command(command, args, sub_command, buffer_args, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
RedisClient.prototype.send_command = function (command, args, callback) {
|
RedisClient.prototype.send_command = function (command, args, callback) {
|
||||||
var arg, this_args, command_obj, i, il, elem_count, buffer_args, stream = this.stream, command_str = "", buffered_writes = 0, last_arg_type;
|
var arg, command_obj, i, il, elem_count, buffer_args, stream = this.stream, command_str = "", buffered_writes = 0, last_arg_type;
|
||||||
|
|
||||||
if (typeof command !== "string") {
|
if (typeof command !== "string") {
|
||||||
throw new Error("First argument to send_command must be the command name string, not " + typeof command);
|
throw new Error("First argument to send_command must be the command name string, not " + typeof command);
|
||||||
@@ -948,8 +946,11 @@ RedisClient.prototype.hmset = function (args, callback) {
|
|||||||
tmp_args.push(key);
|
tmp_args.push(key);
|
||||||
if (typeof args[1][key] !== "string") {
|
if (typeof args[1][key] !== "string") {
|
||||||
var err = new Error("hmset expected value to be a string", key, ":", args[1][key]);
|
var err = new Error("hmset expected value to be a string", key, ":", args[1][key]);
|
||||||
if (callback) return callback(err);
|
if (callback) {
|
||||||
else throw err;
|
return callback(err);
|
||||||
|
} else {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
tmp_args.push(args[1][key]);
|
tmp_args.push(args[1][key]);
|
||||||
}
|
}
|
||||||
@@ -1027,7 +1028,7 @@ Multi.prototype.exec = function (callback) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var i, il, j, jl, reply, args;
|
var i, il, reply, args;
|
||||||
|
|
||||||
if (replies) {
|
if (replies) {
|
||||||
for (i = 1, il = self.queue.length; i < il; i += 1) {
|
for (i = 1, il = self.queue.length; i < il; i += 1) {
|
||||||
@@ -1061,10 +1062,9 @@ RedisClient.prototype.MULTI = function (args) {
|
|||||||
|
|
||||||
|
|
||||||
// stash original eval method
|
// stash original eval method
|
||||||
var eval = RedisClient.prototype.eval;
|
var eval_orig = RedisClient.prototype.eval;
|
||||||
// hook eval with an attempt to evalsha for cached scripts
|
// hook eval with an attempt to evalsha for cached scripts
|
||||||
RedisClient.prototype.eval =
|
RedisClient.prototype.eval = RedisClient.prototype.EVAL = function () {
|
||||||
RedisClient.prototype.EVAL = function () {
|
|
||||||
var self = this,
|
var self = this,
|
||||||
args = to_array(arguments),
|
args = to_array(arguments),
|
||||||
callback;
|
callback;
|
||||||
@@ -1080,7 +1080,7 @@ RedisClient.prototype.EVAL = function () {
|
|||||||
self.evalsha(args, function (err, reply) {
|
self.evalsha(args, function (err, reply) {
|
||||||
if (err && /NOSCRIPT/.test(err.message)) {
|
if (err && /NOSCRIPT/.test(err.message)) {
|
||||||
args[0] = source;
|
args[0] = source;
|
||||||
eval.call(self, args, callback);
|
eval_orig.call(self, args, callback);
|
||||||
|
|
||||||
} else if (callback) {
|
} else if (callback) {
|
||||||
callback(err, reply);
|
callback(err, reply);
|
||||||
|
@@ -1,5 +1,3 @@
|
|||||||
/*global Buffer require exports console setTimeout */
|
|
||||||
|
|
||||||
var events = require("events"),
|
var events = require("events"),
|
||||||
util = require("../util"),
|
util = require("../util"),
|
||||||
hiredis = require("hiredis");
|
hiredis = require("hiredis");
|
||||||
@@ -29,13 +27,15 @@ HiredisReplyParser.prototype.execute = function (data) {
|
|||||||
this.reader.feed(data);
|
this.reader.feed(data);
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
reply = this.reader.get();
|
reply = this.reader.get();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.emit("error", err);
|
this.emit("error", err);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reply === undefined) break;
|
if (reply === undefined) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (reply && reply.constructor === Error) {
|
if (reply && reply.constructor === Error) {
|
||||||
this.emit("reply error", reply);
|
this.emit("reply error", reply);
|
||||||
|
@@ -1,28 +1,28 @@
|
|||||||
var events = require("events"),
|
var events = require("events"),
|
||||||
util = require('../util');
|
util = require("../util");
|
||||||
|
|
||||||
function Packet (type, size) {
|
function Packet(type, size) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.size = +size;
|
this.size = +size;
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.name = 'faster';
|
exports.name = "faster";
|
||||||
exports.debug_mode = false;
|
exports.debug_mode = false;
|
||||||
|
|
||||||
function FasterReplyParser (options) {
|
function ReplyParser(options) {
|
||||||
this.name = exports.name;
|
this.name = exports.name;
|
||||||
this.options = options || { };
|
this.options = options || { };
|
||||||
|
|
||||||
this._buffer = null;
|
this._buffer = null;
|
||||||
this._offset = 0;
|
this._offset = 0;
|
||||||
this._encoding = 'utf-8';
|
this._encoding = "utf-8";
|
||||||
this._debug_mode = options.debug_mode;
|
this._debug_mode = options.debug_mode;
|
||||||
this._reply_type = null;
|
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
|
// Buffer.toString() is quite slow for small strings
|
||||||
function small_toString(buf, start, end) {
|
function small_toString(buf, start, end) {
|
||||||
@@ -35,7 +35,7 @@ function small_toString(buf, start, end) {
|
|||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
FasterReplyParser.prototype._parseResult = function (type) {
|
ReplyParser.prototype._parseResult = function (type) {
|
||||||
var start, end, offset, packetHeader;
|
var start, end, offset, packetHeader;
|
||||||
|
|
||||||
if (type === 43 || type === 45) { // + or -
|
if (type === 43 || type === 45) { // + or -
|
||||||
@@ -77,7 +77,6 @@ FasterReplyParser.prototype._parseResult = function (type) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
end = this._offset + packetHeader.size;
|
end = this._offset + packetHeader.size;
|
||||||
start = this._offset;
|
start = this._offset;
|
||||||
|
|
||||||
@@ -117,7 +116,7 @@ FasterReplyParser.prototype._parseResult = function (type) {
|
|||||||
ntype = this._buffer[this._offset++];
|
ntype = this._buffer[this._offset++];
|
||||||
|
|
||||||
if (this._offset === this._buffer.length) {
|
if (this._offset === this._buffer.length) {
|
||||||
throw new Error('too far');
|
throw new Error("too far");
|
||||||
}
|
}
|
||||||
reply.push(this._parseResult(ntype));
|
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);
|
this.append(buffer);
|
||||||
|
|
||||||
var type, ret, offset;
|
var type, ret, offset;
|
||||||
@@ -140,13 +139,12 @@ FasterReplyParser.prototype.execute = function (buffer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type = this._buffer[this._offset++];
|
type = this._buffer[this._offset++];
|
||||||
|
|
||||||
|
|
||||||
if (type === 43) { // +
|
if (type === 43) { // +
|
||||||
ret = this._parseResult(type);
|
ret = this._parseResult(type);
|
||||||
|
|
||||||
if (ret === null) {
|
if (ret === null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.send_reply(ret);
|
this.send_reply(ret);
|
||||||
@@ -154,7 +152,7 @@ FasterReplyParser.prototype.execute = function (buffer) {
|
|||||||
ret = this._parseResult(type);
|
ret = this._parseResult(type);
|
||||||
|
|
||||||
if (ret === null) {
|
if (ret === null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.send_error(ret);
|
this.send_error(ret);
|
||||||
@@ -162,7 +160,7 @@ FasterReplyParser.prototype.execute = function (buffer) {
|
|||||||
ret = this._parseResult(type);
|
ret = this._parseResult(type);
|
||||||
|
|
||||||
if (ret === null) {
|
if (ret === null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.send_reply(+ret);
|
this.send_reply(+ret);
|
||||||
@@ -170,7 +168,7 @@ FasterReplyParser.prototype.execute = function (buffer) {
|
|||||||
ret = this._parseResult(type);
|
ret = this._parseResult(type);
|
||||||
|
|
||||||
if (ret === null) {
|
if (ret === null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.send_reply(ret);
|
this.send_reply(ret);
|
||||||
@@ -188,16 +186,16 @@ FasterReplyParser.prototype.execute = function (buffer) {
|
|||||||
|
|
||||||
this.send_reply(ret);
|
this.send_reply(ret);
|
||||||
}
|
}
|
||||||
} catch(err) {
|
} catch (err) {
|
||||||
// catch the error (not enough data), rewind, and wait
|
// catch the error (not enough data), rewind, and wait
|
||||||
// for the next packet to appear
|
// for the next packet to appear
|
||||||
this._offset = offset;
|
this._offset = offset;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
FasterReplyParser.prototype.append = function(newBuffer) {
|
ReplyParser.prototype.append = function (newBuffer) {
|
||||||
if (!newBuffer) {
|
if (!newBuffer) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -235,42 +233,42 @@ FasterReplyParser.prototype.append = function(newBuffer) {
|
|||||||
this._offset = 0;
|
this._offset = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
FasterReplyParser.prototype.parseHeader = function () {
|
ReplyParser.prototype.parseHeader = function () {
|
||||||
var end = this._packetEndOffset(),
|
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;
|
this._offset = end + 1;
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
};
|
};
|
||||||
|
|
||||||
FasterReplyParser.prototype._packetEndOffset = function () {
|
ReplyParser.prototype._packetEndOffset = function () {
|
||||||
var offset = this._offset;
|
var offset = this._offset;
|
||||||
|
|
||||||
while (this._buffer[offset] !== 0x0d && this._buffer[offset + 1] !== 0x0a) {
|
while (this._buffer[offset] !== 0x0d && this._buffer[offset + 1] !== 0x0a) {
|
||||||
offset++;
|
offset++;
|
||||||
|
|
||||||
if (offset >= this._buffer.length) {
|
if (offset >= this._buffer.length) {
|
||||||
throw new Error("didn't see LF after NL reading multi bulk count (" + offset + " => " + this._buffer.length + ", " + this._offset + ")");
|
throw new Error("didn't see LF after NL reading multi bulk count (" + offset + " => " + this._buffer.length + ", " + this._offset + ")");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
offset++;
|
offset++;
|
||||||
return offset;
|
return offset;
|
||||||
};
|
};
|
||||||
|
|
||||||
FasterReplyParser.prototype._bytesRemaining = function() {
|
ReplyParser.prototype._bytesRemaining = function () {
|
||||||
return (this._buffer.length - this._offset) < 0 ? 0 : (this._buffer.length - this._offset);
|
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);
|
this.emit("error", message);
|
||||||
};
|
};
|
||||||
|
|
||||||
FasterReplyParser.prototype.send_error = function (reply) {
|
ReplyParser.prototype.send_error = function (reply) {
|
||||||
this.emit("reply error", reply);
|
this.emit("reply error", reply);
|
||||||
};
|
};
|
||||||
|
|
||||||
FasterReplyParser.prototype.send_reply = function (reply) {
|
ReplyParser.prototype.send_reply = function (reply) {
|
||||||
this.emit("reply", reply);
|
this.emit("reply", reply);
|
||||||
};
|
};
|
@@ -1,5 +1,3 @@
|
|||||||
var to_array = require("./to_array");
|
|
||||||
|
|
||||||
// Queue class adapted from Tim Caswell's pattern library
|
// Queue class adapted from Tim Caswell's pattern library
|
||||||
// http://github.com/creationix/pattern/blob/master/lib/pattern/queue.js
|
// 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;
|
return this.head.length - this.offset + this.tail.length;
|
||||||
};
|
};
|
||||||
|
|
||||||
Object.defineProperty(Queue.prototype, 'length', {
|
Object.defineProperty(Queue.prototype, "length", {
|
||||||
get: function () {
|
get: function () {
|
||||||
return this.getLength();
|
return this.getLength();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
if(typeof module !== 'undefined' && module.exports) {
|
if (typeof module !== "undefined" && module.exports) {
|
||||||
module.exports = Queue;
|
module.exports = Queue;
|
||||||
}
|
}
|
||||||
|
@@ -28,8 +28,6 @@ metrics.Histogram.prototype.print_line = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function Test(args) {
|
function Test(args) {
|
||||||
var self = this;
|
|
||||||
|
|
||||||
this.args = args;
|
this.args = args;
|
||||||
|
|
||||||
this.callback = null;
|
this.callback = null;
|
||||||
@@ -46,7 +44,7 @@ function Test(args) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Test.prototype.run = function (callback) {
|
Test.prototype.run = function (callback) {
|
||||||
var self = this, i;
|
var i;
|
||||||
|
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
|
|
||||||
@@ -120,7 +118,6 @@ Test.prototype.stop_clients = function () {
|
|||||||
Test.prototype.send_next = function () {
|
Test.prototype.send_next = function () {
|
||||||
var self = this,
|
var self = this,
|
||||||
cur_client = this.commands_sent % this.clients.length,
|
cur_client = this.commands_sent % this.clients.length,
|
||||||
command_num = this.commands_sent,
|
|
||||||
start = Date.now();
|
start = Date.now();
|
||||||
|
|
||||||
this.clients[cur_client][this.args.command](this.args.args, function (err, res) {
|
this.clients[cur_client][this.args.command](this.args.args, function (err, res) {
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{ "name" : "redis",
|
{ "name" : "redis",
|
||||||
"version" : "0.7.2",
|
"version" : "0.8.0",
|
||||||
"description" : "Redis client library, battle-tested by Voxer.com",
|
"description" : "Redis client library, battle-tested by Voxer",
|
||||||
"keywords" : [ "redis", "pub", "sub", "voxer", "database" ],
|
"keywords" : [ "redis", "pub", "sub", "voxer", "database" ],
|
||||||
"author": "Matt Ranney <mjr@ranney.com>",
|
"author": "Matt Ranney <mjr@ranney.com>",
|
||||||
"main": "./index.js",
|
"main": "./index.js",
|
||||||
|
Reference in New Issue
Block a user