1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00

JSLint fixes.

This commit is contained in:
Matt Ranney
2010-10-20 16:38:47 -07:00
parent 1c5f73f541
commit 645a981231

View File

@@ -7,6 +7,7 @@ var net = require("net"),
default_host = "127.0.0.1", default_host = "127.0.0.1",
commands; commands;
// can can set this to true to enable for all connections
exports.debug_mode = false; exports.debug_mode = false;
function RedisReplyParser() { function RedisReplyParser() {
@@ -17,9 +18,9 @@ sys.inherits(RedisReplyParser, events.EventEmitter);
// Buffer.toString() is quite slow for small strings // Buffer.toString() is quite slow for small strings
function small_toString(buf) { function small_toString(buf) {
var tmp = ""; var tmp = "", i, il;
for (var i = 0, il = buf.end; i < il; i++) { for (i = 0, il = buf.end; i < il; i += 1) {
tmp += String.fromCharCode(buf[i]); tmp += String.fromCharCode(buf[i]);
} }
@@ -38,7 +39,7 @@ function to_array(args) {
} }
// Reset parser to it's original state. // Reset parser to it's original state.
RedisReplyParser.prototype.reset = function() { RedisReplyParser.prototype.reset = function () {
this.state = "type"; this.state = "type";
this.return_buffer = new Buffer(16384); // for holding replies, might grow this.return_buffer = new Buffer(16384); // for holding replies, might grow
@@ -48,10 +49,10 @@ RedisReplyParser.prototype.reset = function() {
this.multi_bulk_replies = null; this.multi_bulk_replies = null;
this.multi_bulk_nested_length = 0; this.multi_bulk_nested_length = 0;
this.multi_bulk_nested_replies = null; this.multi_bulk_nested_replies = null;
} };
RedisReplyParser.prototype.execute = function (incoming_buf) { RedisReplyParser.prototype.execute = function (incoming_buf) {
var pos = 0, bd_tmp, bd_str, i; var pos = 0, bd_tmp, bd_str, i, il;
//, state_times = {}, start_execute = new Date(), start_switch, end_switch, old_state; //, state_times = {}, start_execute = new Date(), start_switch, end_switch, old_state;
//start_switch = new Date(); //start_switch = new Date();
@@ -201,7 +202,7 @@ RedisReplyParser.prototype.execute = function (incoming_buf) {
if (this.bulk_length > 10) { if (this.bulk_length > 10) {
this.return_buffer.copy(bd_tmp, 0, 0, this.bulk_length); this.return_buffer.copy(bd_tmp, 0, 0, this.bulk_length);
} else { } else {
for (var i = 0, il = this.bulk_length; i < il; i++) { for (i = 0, il = this.bulk_length; i < il; i += 1) {
bd_tmp[i] = this.return_buffer[i]; bd_tmp[i] = this.return_buffer[i];
} }
} }
@@ -308,7 +309,7 @@ Queue.prototype.shift = function () {
return; return;
} }
} }
return this.head[this.offset++]; return this.head[this.offset++]; // sorry, JSLint
}; };
Queue.prototype.push = function (item) { Queue.prototype.push = function (item) {
@@ -316,15 +317,16 @@ Queue.prototype.push = function (item) {
}; };
Queue.prototype.forEach = function (fn, thisv) { Queue.prototype.forEach = function (fn, thisv) {
var array = this.head.slice(this.offset); var array = this.head.slice(this.offset), i, il;
array.push.apply(array, this.tail); array.push.apply(array, this.tail);
if (thisv) { if (thisv) {
for (var i = 0, il = array.length; i < il; i++) { for (i = 0, il = array.length; i < il; i += 1) {
fn.call(thisv, array[i], i, array); fn.call(thisv, array[i], i, array);
} }
} else { } else {
for (var i = 0, il = array.length; i < il; i++) { for (i = 0, il = array.length; i < il; i += 1) {
fn(array[i], i, array); fn(array[i], i, array);
} }
} }
@@ -543,7 +545,7 @@ RedisClient.prototype.return_reply = function (reply) {
}; };
RedisClient.prototype.send_command = function () { RedisClient.prototype.send_command = function () {
var command, callback, args, this_args, command_obj, var command, callback, arg, args, this_args, command_obj, i, il,
elem_count, stream = this.stream, buffer_args, command_str = ""; elem_count, stream = this.stream, buffer_args, command_str = "";
this_args = to_array(arguments); this_args = to_array(arguments);
@@ -615,7 +617,7 @@ RedisClient.prototype.send_command = function () {
command_str = "*" + elem_count + "\r\n$" + command.length + "\r\n" + command + "\r\n"; command_str = "*" + elem_count + "\r\n$" + command.length + "\r\n" + command + "\r\n";
if (! buffer_args) { // Build up a string and send entire command in one write if (! buffer_args) { // Build up a string and send entire command in one write
for (var i = 0, il = args.length, arg; i < il; i++) { for (i = 0, il = args.length, arg; i < il; i += 1) {
arg = args[i]; arg = args[i];
if (typeof arg !== "string") { if (typeof arg !== "string") {
arg = String(arg); arg = String(arg);
@@ -634,7 +636,7 @@ RedisClient.prototype.send_command = function () {
} }
stream.write(command_str); stream.write(command_str);
for (var i = 0, il = args.length, arg; i < il; i++) { for (i = 0, il = args.length, arg; i < il; i += 1) {
arg = args[i]; arg = args[i];
if (arg.length === undefined) { if (arg.length === undefined) {
arg = String(arg); arg = String(arg);
@@ -692,7 +694,7 @@ commands = [
// Publish/Subscribe // Publish/Subscribe
"PUBLISH", "SUBSCRIBE", "PSUBSCRIBE", "UNSUBSCRIBE", "PUNSUBSCRIBE", "PUBLISH", "SUBSCRIBE", "PSUBSCRIBE", "UNSUBSCRIBE", "PUNSUBSCRIBE",
// Undocumented commands // Undocumented commands
"PING", "PING"
]; ];
commands.forEach(function (command) { commands.forEach(function (command) {
@@ -721,12 +723,12 @@ commands.forEach(function (command) {
}; };
}); });
Multi.prototype.exec = function(callback) { Multi.prototype.exec = function (callback) {
var done = false, self = this; var self = this;
// drain queue, callback will catch "QUEUED" or error // drain queue, callback will catch "QUEUED" or error
// Can't use a for loop here, as we need closure around the index. // Can't use a for loop here, as we need closure around the index.
this.queue.forEach(function(args, index) { this.queue.forEach(function (args, index) {
var command = args[0]; var command = args[0];
if (typeof args[args.length - 1] === "function") { if (typeof args[args.length - 1] === "function") {
args = args.slice(1, -1); args = args.slice(1, -1);
@@ -734,12 +736,12 @@ Multi.prototype.exec = function(callback) {
args = args.slice(1); args = args.slice(1);
} }
if (args.length === 1 && Array.isArray(args[0])) { if (args.length === 1 && Array.isArray(args[0])) {
args = args[0]; args = args[0];
} }
this.client.send_command(command, args, function (err, reply){ this.client.send_command(command, args, function (err, reply) {
if (err) { if (err) {
var cur = self.queue[index]; var cur = self.queue[index];
if (typeof cur[cur.length -1] === "function") { if (typeof cur[cur.length - 1] === "function") {
cur[cur.length - 1](err); cur[cur.length - 1](err);
} else { } else {
throw new Error(err); throw new Error(err);
@@ -758,14 +760,16 @@ Multi.prototype.exec = function(callback) {
} }
} }
for (var i = 1, il = self.queue.length; i < il; i++) { var i, il, j, jl, reply, args, obj, key, val;
var reply = replies[i - 1],
args = self.queue[i]; for (i = 1, il = self.queue.length; i < il; i += 1) {
reply = replies[i - 1];
args = self.queue[i];
// Convert HGETALL reply to object // Convert HGETALL reply to object
if (reply && args[0] === "HGETALL") { if (reply && args[0] === "HGETALL") {
obj = {}; obj = {};
for (var j = 0, jl = reply.length; j < jl; j += 2) { for (j = 0, jl = reply.length; j < jl; j += 2) {
key = reply[j].toString(); key = reply[j].toString();
val = reply[j + 1]; val = reply[j + 1];
obj[key] = val; obj[key] = val;