1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-10 11:43:01 +03:00

Merge pull request #785 from fintura/master

Add "use strict", semicolons, whitespace & code cleanup, remove util.print.
This commit is contained in:
Erin Spiceland
2015-08-06 11:11:13 -05:00
39 changed files with 130 additions and 62 deletions

View File

@@ -1,6 +1,8 @@
'use strict';
var source = new Buffer(100),
dest = new Buffer(100), i, j, k, tmp, count = 1000000, bytes = 100;
for (i = 99 ; i >= 0 ; i--) {
source[i] = 120;
}

View File

@@ -1,3 +1,5 @@
'use strict';
var Parser = require('../lib/parser/hiredis').Parser;
var assert = require('assert');

View File

@@ -1,3 +1,5 @@
'use strict';
var client = require('../index').createClient()
, client2 = require('../index').createClient()
, assert = require('assert');

View File

@@ -1,3 +1,5 @@
'use strict';
var redis = require("../index").createClient(null, null, {
// max_attempts: 4
});

View File

@@ -1,16 +1,8 @@
'use strict';
var json = {
encode: JSON.stringify,
decode: JSON.parse
};
var MsgPack = require('node-msgpack');
msgpack = {
encode: MsgPack.pack,
decode: function(str) { return MsgPack.unpack(new Buffer(str)); }
};
bison = require('bison');
module.exports = json;
//module.exports = msgpack;
//module.exports = bison;

View File

@@ -1,3 +1,5 @@
'use strict';
var msgpack = require('node-msgpack');
var bison = require('bison');
var codec = {

View File

@@ -1,3 +1,5 @@
'use strict';
var client = require("redis").createClient(),
client2 = require("redis").createClient();

View File

@@ -1,3 +1,5 @@
'use strict';
var net = require('net');
var proxyPort = 6379;

View File

@@ -1,5 +1,7 @@
#!/usr/bin/env node
'use strict';
var colors = require('colors'),
fs = require('fs'),
_ = require('underscore'),
@@ -35,8 +37,8 @@ before_lines.forEach(function(b, i) {
return;
}
b_words = b.split(' ').filter(is_whitespace);
a_words = a.split(' ').filter(is_whitespace);
var b_words = b.split(' ').filter(is_whitespace);
var a_words = a.split(' ').filter(is_whitespace);
var ops =
[b_words, a_words]
@@ -47,7 +49,7 @@ before_lines.forEach(function(b, i) {
var isNaN = !num && num !== 0;
return !isNaN;
});
if (ops.length != 2) return
if (ops.length !== 2) return;
var delta = ops[1] - ops[0];
var pct = ((delta / ops[0]) * 100).toPrecision(3);
@@ -58,7 +60,7 @@ before_lines.forEach(function(b, i) {
pct = humanize_diff(pct, '%');
console.log(
// name of test
command_name(a_words) == command_name(b_words)
command_name(a_words) === command_name(b_words)
? command_name(a_words) + ':'
: '404:',
// results of test

View File

@@ -1,3 +1,5 @@
'use strict';
var redis = require("redis"),
client = redis.createClient();

View File

@@ -1,3 +1,5 @@
'use strict';
var redis = require("../index"),
client = redis.createClient(null, null, {
command_queue_high_water: 5,

View File

@@ -1,3 +1,5 @@
'use strict';
var redis = require("../index"),
client = redis.createClient();

View File

@@ -1,3 +1,5 @@
'use strict';
var redis = require("redis"),
client = redis.createClient();
@@ -14,7 +16,7 @@ redis.RedisClient.prototype.parse_info = function (callback) {
obj[parts[0]] = parts[1];
}
});
callback(obj)
callback(obj);
});
};

View File

@@ -1,3 +1,5 @@
'use strict';
// Read a file from disk, store it in Redis, then read it back from Redis.
var redis = require("redis"),
@@ -11,9 +13,9 @@ var redis = require("redis"),
// Read a file from fs, store it in Redis, get it back from Redis, write it back to fs.
fs.readFile(filename, function (err, data) {
if (err) throw err
if (err) throw err;
console.log("Read " + data.length + " bytes from filesystem.");
client.set(filename, data, redis.print); // set entire file
client.get(filename, function (err, reply) { // get entire file
if (err) {
@@ -21,7 +23,7 @@ fs.readFile(filename, function (err, data) {
} else {
fs.writeFile("duplicate_" + filename, reply, function (err) {
if (err) {
console.log("Error on write: " + err)
console.log("Error on write: " + err);
} else {
console.log("File written.");
}

View File

@@ -1,3 +1,5 @@
'use strict';
var client = require("redis").createClient();
client.mget(["sessions started", "sessions started", "foo"], function (err, res) {

View File

@@ -1,3 +1,5 @@
'use strict';
var client = require("../index").createClient(),
util = require("util");

View File

@@ -1,3 +1,5 @@
'use strict';
var redis = require("redis"),
client = redis.createClient(), set_size = 20;

View File

@@ -1,3 +1,5 @@
'use strict';
var redis = require("redis"),
client = redis.createClient(), multi;

View File

@@ -1,3 +1,5 @@
'use strict';
var redis = require("redis"),
client1 = redis.createClient(),
client2 = redis.createClient(),

View File

@@ -1,3 +1,5 @@
'use strict';
var redis = require("redis"),
client1 = redis.createClient(), msg_count = 0,
client2 = redis.createClient();

View File

@@ -1,3 +1,5 @@
'use strict';
var redis = require("redis"),
client = redis.createClient();

View File

@@ -1,3 +1,5 @@
'use strict';
var redis = require("redis"),
client = redis.createClient();

View File

@@ -1,3 +1,5 @@
'use strict';
var redis = require("redis"),
client = redis.createClient();

View File

@@ -1,3 +1,5 @@
'use strict';
// Sending commands in response to other commands.
// This example runs "type" against every key in the database
//

View File

@@ -1,3 +1,5 @@
'use strict';
var client = require("redis").createClient();
function print_results(obj) {
@@ -7,7 +9,7 @@ function print_results(obj) {
// build a map of all keys and their types
client.keys("*", function (err, all_keys) {
var key_types = {};
all_keys.forEach(function (key, pos) { // use second arg of forEach to get pos
client.type(key, function (err, type) {
key_types[key] = type;

View File

@@ -1,9 +1,11 @@
'use strict';
var redis = require("redis"),
client = redis.createClient("/tmp/redis.sock"),
profiler = require("v8-profiler");
client.on("connect", function () {
console.log("Got Unix socket connection.")
console.log("Got Unix socket connection.");
});
client.on("error", function (err) {

View File

@@ -1,3 +1,5 @@
'use strict';
// A simple web server that generates dyanmic content based on responses from Redis
var http = require("http"), server,
@@ -7,9 +9,9 @@ server = http.createServer(function (request, response) {
response.writeHead(200, {
"Content-Type": "text/plain"
});
var redis_info, total_requests;
redis_client.info(function (err, reply) {
redis_info = reply; // stash response in outer scope
});

View File

@@ -1,3 +1,5 @@
'use strict';
var http = require("http"),
fs = require("fs");

View File

@@ -1,3 +1,5 @@
'use strict';
/*global Buffer require exports console setTimeout */
var net = require("net"),
@@ -15,10 +17,10 @@ var net = require("net"),
// can set this to true to enable for all connections
exports.debug_mode = false;
var arraySlice = Array.prototype.slice
var arraySlice = Array.prototype.slice;
function trace() {
if (!exports.debug_mode) return;
console.log.apply(null, arraySlice.call(arguments))
console.log.apply(null, arraySlice.call(arguments));
}
// hiredis might not be installed
@@ -139,7 +141,7 @@ RedisClient.prototype.unref = function () {
trace("Not connected yet, will unref later");
this.once("connect", function () {
this.unref();
})
});
}
};
@@ -217,7 +219,7 @@ RedisClient.prototype.do_auth = function () {
}, 2000); // TODO - magic number alert
return;
} else if (err.toString().match("no password is set")) {
console.log("Warning: Redis server does not require a password, but a password was supplied.")
console.log("Warning: Redis server does not require a password, but a password was supplied.");
err = null;
res = "OK";
} else {
@@ -1263,7 +1265,7 @@ var createClient_unix = function(path, options){
redis_client.address = path;
return redis_client;
}
};
var createClient_tcp = function (port_arg, host_arg, options) {
var cnxOptions = {

View File

@@ -1,3 +1,5 @@
'use strict';
// This file was generated by ./generate_commands.js on Wed Apr 23 2014 14:51:21 GMT-0700 (PDT)
module.exports = [
"append",

View File

@@ -1,3 +1,5 @@
'use strict';
var events = require("events"),
util = require("../util"),
hiredis = require("hiredis");

View File

@@ -1,3 +1,5 @@
'use strict';
var events = require("events"),
util = require("../util");

View File

@@ -1,3 +1,5 @@
'use strict';
// Queue class adapted from Tim Caswell's pattern library
// http://github.com/creationix/pattern/blob/master/lib/pattern/queue.js

View File

@@ -1,3 +1,5 @@
'use strict';
function to_array(args) {
var len = args.length,
arr = new Array(len), i;

View File

@@ -1,3 +1,5 @@
'use strict';
// Support for very old versions of node where the module was called "sys". At some point, we should abandon this.
var util;

View File

@@ -1,3 +1,5 @@
'use strict';
var redis = require("./index"),
metrics = require("metrics"),
num_clients = parseInt(process.argv[2], 10) || 5,
@@ -23,13 +25,13 @@ function lpad(input, len, chr) {
metrics.Histogram.prototype.print_line = function () {
var obj = this.printObj();
return lpad(obj.min, 4) + "/" + lpad(obj.max, 4) + "/" + lpad(obj.mean.toFixed(2), 7) + "/" + lpad(obj.p95.toFixed(2), 7);
};
function Test(args) {
this.args = args;
this.callback = null;
this.clients = [];
this.clients_ready = 0;
@@ -56,7 +58,7 @@ Test.prototype.run = function (callback) {
Test.prototype.new_client = function (id) {
var self = this, new_client;
new_client = redis.createClient(6379, "127.0.0.1", this.client_options);
new_client.create_time = Date.now();
@@ -95,7 +97,7 @@ Test.prototype.fill_pipeline = function () {
pipeline++;
this.send_next();
}
if (this.commands_completed === this.num_requests) {
this.print_stats();
this.stop_clients();
@@ -104,7 +106,7 @@ Test.prototype.fill_pipeline = function () {
Test.prototype.stop_clients = function () {
var self = this;
this.clients.forEach(function (client, pos) {
if (pos === self.clients.length - 1) {
client.quit(function (err, res) {
@@ -133,7 +135,7 @@ Test.prototype.send_next = function () {
Test.prototype.print_stats = function () {
var duration = Date.now() - this.test_start;
console.log("min/max/avg/p95: " + this.command_latency.print_line() + " " + lpad(duration, 6) + "ms total, " +
lpad((this.num_requests / (duration / 1000)).toFixed(2), 8) + " ops/sec");
};

View File

@@ -1,3 +1,5 @@
'use strict';
var assert = require("assert");
var Queue = require('../lib/queue');
@@ -9,12 +11,12 @@ module.exports = function (tests, next) {
q.push(3);
assert.equal(q.length, 2);
return next();
}
};
tests.shift = function () {
assert.equal(q.shift(), 'a');
return next();
}
};
tests.forEach = function () {
q.forEach(function (v) {
@@ -22,7 +24,7 @@ module.exports = function (tests, next) {
});
return next();
}
};
tests.forEachWithScope = function () {
q.forEach(function (v) {
@@ -31,5 +33,5 @@ module.exports = function (tests, next) {
}, {foo: 'bar'});
return next();
}
}
};
};

View File

@@ -1,12 +1,14 @@
var redis = require("../")
'use strict';
var redis = require("../");
//redis.debug_mode = true
var PORT = process.argv[2] || 6379;
var HOST = process.argv[3] || '127.0.0.1';
var c = redis.createClient(PORT, HOST)
c.unref()
var c = redis.createClient(PORT, HOST);
c.unref();
c.info(function (err, reply) {
if (err) process.exit(-1)
if (!reply.length) process.exit(-1)
process.stdout.write(reply.length.toString())
})
if (err) process.exit(-1);
if (!reply.length) process.exit(-1);
process.stdout.write(reply.length.toString());
});

View File

@@ -1,3 +1,5 @@
'use strict';
/*global require console setTimeout process Buffer */
var PORT = process.env.REDIS_PORT_6379_TCP_PORT || 6379;
var HOST = process.env.REDIS_PORT_6379_TCP_ADDR || '127.0.0.1';
@@ -136,7 +138,7 @@ tests.IPV4 = function () {
console.error("client: " + err.stack);
process.exit();
});
}
};
tests.IPV6 = function () {
if (!server_version_at_least(client, [2, 8, 0])) {
@@ -163,7 +165,7 @@ tests.IPV6 = function () {
console.error("client: " + err.stack);
process.exit();
});
}
};
tests.UNIX_SOCKET = function () {
var unixClient = redis.createClient('/tmp/redis.sock', { parser: parser });
@@ -189,7 +191,7 @@ tests.UNIX_SOCKET = function () {
console.error("client: " + err.stack);
process.exit();
});
}
};
tests.FLUSHDB = function () {
var name = "FLUSHDB";
@@ -204,7 +206,7 @@ tests.FLUSHDB = function () {
tests.INCR = function () {
var name = "INCR";
if (bclient.reply_parser.name == "hiredis") {
if (bclient.reply_parser.name === "hiredis") {
console.log("Skipping INCR buffer test with hiredis");
return next(name);
}
@@ -371,7 +373,7 @@ tests.MULTI_6 = function () {
tests.MULTI_7 = function () {
var name = "MULTI_7";
if (bclient.reply_parser.name != "javascript") {
if (bclient.reply_parser.name !== "javascript") {
console.log("Skipping wire-protocol test for 3rd-party parser");
return next(name);
}
@@ -467,7 +469,7 @@ tests.FWD_ERRORS_1 = function () {
client3.on("message", function (channel, data) {
console.log("incoming");
if (channel == name) {
if (channel === name) {
assert.equal(data, "Some message");
throw toThrow;
}
@@ -1286,11 +1288,11 @@ tests.SUBSCRIBE_CLOSE_RESUBSCRIBE = function () {
console.log("c1 is ready", count);
count++;
if (count == 1) {
if (count === 1) {
c2.publish("chan1", "hi on channel 1");
return;
} else if (count == 2) {
} else if (count === 2) {
c2.publish("chan2", "hi on channel 2");
} else {
@@ -1543,7 +1545,7 @@ tests.HGETALL_MESSAGE = function () {
client.hgetall("msg_test", function (err, obj) {
assert.strictEqual(null, err, name + " result sent back unexpected error: " + err);
assert.strictEqual(1, Object.keys(obj).length, name);
assert.strictEqual(obj.message, "hello")
assert.strictEqual(obj.message, "hello");
next(name);
});
};
@@ -2178,8 +2180,8 @@ tests.ENABLE_OFFLINE_QUEUE_FALSE = function () {
// ignore, see above
});
assert.throws(function () {
cli.set(name, name)
})
cli.set(name, name);
});
assert.doesNotThrow(function () {
cli.set(name, name, function (err) {
// should callback with an error
@@ -2205,7 +2207,7 @@ tests.SLOWLOG = function () {
client.config("set", "slowlog-log-slower-than", 10000, require_string("OK", name));
next(name);
});
}
};
tests.DOMAIN = function () {
var name = "DOMAIN";
@@ -2323,9 +2325,9 @@ tests.unref = function () {
var external = fork("./test/test-unref.js", [PORT, HOST]);
var done = false;
external.on("close", function (code) {
assert(code == 0, "test-unref.js failed");
assert(code === 0, "test-unref.js failed");
done = true;
})
});
setTimeout(function () {
if (!done) {
external.kill();
@@ -2336,7 +2338,7 @@ tests.unref = function () {
};
// starting to split tests into multiple files.
require('./queue-test')(tests, next)
require('./queue-test')(tests, next);
all_tests = Object.keys(tests);
all_start = new Date();
@@ -2345,7 +2347,7 @@ test_count = 0;
run_next_test = function run_next_test() {
var test_name = all_tests.shift();
if (typeof tests[test_name] === "function") {
util.print('- \x1b[1m' + test_name.toLowerCase() + '\x1b[0m:');
console.log('- \x1b[1m' + test_name.toLowerCase() + '\x1b[0m:');
cur_start = new Date();
test_count += 1;
tests[test_name]();