From 1f9e536ca0cae200b621145a096ef15e3161c4c4 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Wed, 22 Jul 2015 16:17:02 +0200 Subject: [PATCH 1/6] Add use strict statements This is going to improve the performance minimal and improves the safety of the code --- benches/buffer_bench.js | 2 ++ benches/hiredis_parser.js | 2 ++ benches/re_sub_test.js | 2 ++ benches/reconnect_test.js | 2 ++ benches/stress/codec.js | 2 ++ benches/stress/speed/speed.js | 2 ++ benches/sub_quit_test.js | 2 ++ connection_breaker.js | 2 ++ diff_multi_bench_output.js | 2 ++ examples/auth.js | 2 ++ examples/backpressure_drain.js | 2 ++ examples/eval.js | 2 ++ examples/extend.js | 2 ++ examples/file.js | 2 ++ examples/mget.js | 2 ++ examples/monitor.js | 2 ++ examples/multi.js | 2 ++ examples/multi2.js | 2 ++ examples/psubscribe.js | 2 ++ examples/pub_sub.js | 2 ++ examples/scan.js | 2 ++ examples/simple.js | 2 ++ examples/sort.js | 2 ++ examples/subqueries.js | 2 ++ examples/subquery.js | 2 ++ examples/web_server.js | 6 ++++-- generate_commands.js | 2 ++ index.js | 2 ++ lib/commands.js | 2 ++ lib/parser/hiredis.js | 2 ++ lib/parser/javascript.js | 2 ++ lib/queue.js | 2 ++ lib/to_array.js | 2 ++ lib/util.js | 2 ++ multi_bench.js | 2 ++ test/queue-test.js | 2 ++ test/test.js | 2 ++ 37 files changed, 76 insertions(+), 2 deletions(-) diff --git a/benches/buffer_bench.js b/benches/buffer_bench.js index a504fbc0876..df16d90bf4a 100644 --- a/benches/buffer_bench.js +++ b/benches/buffer_bench.js @@ -1,3 +1,5 @@ +'use strict'; + var source = new Buffer(100), dest = new Buffer(100), i, j, k, tmp, count = 1000000, bytes = 100; diff --git a/benches/hiredis_parser.js b/benches/hiredis_parser.js index f1515b110b6..489a4912e2c 100644 --- a/benches/hiredis_parser.js +++ b/benches/hiredis_parser.js @@ -1,3 +1,5 @@ +'use strict'; + var Parser = require('../lib/parser/hiredis').Parser; var assert = require('assert'); diff --git a/benches/re_sub_test.js b/benches/re_sub_test.js index 64b8f31287f..256d0d0d1d6 100644 --- a/benches/re_sub_test.js +++ b/benches/re_sub_test.js @@ -1,3 +1,5 @@ +'use strict'; + var client = require('../index').createClient() , client2 = require('../index').createClient() , assert = require('assert'); diff --git a/benches/reconnect_test.js b/benches/reconnect_test.js index 7abdd516651..7556ea430a4 100644 --- a/benches/reconnect_test.js +++ b/benches/reconnect_test.js @@ -1,3 +1,5 @@ +'use strict'; + var redis = require("../index").createClient(null, null, { // max_attempts: 4 }); diff --git a/benches/stress/codec.js b/benches/stress/codec.js index 7d764f60728..c679a6ee016 100644 --- a/benches/stress/codec.js +++ b/benches/stress/codec.js @@ -1,3 +1,5 @@ +'use strict'; + var json = { encode: JSON.stringify, decode: JSON.parse diff --git a/benches/stress/speed/speed.js b/benches/stress/speed/speed.js index 8e43cbc03b9..93d54f0c133 100644 --- a/benches/stress/speed/speed.js +++ b/benches/stress/speed/speed.js @@ -1,3 +1,5 @@ +'use strict'; + var msgpack = require('node-msgpack'); var bison = require('bison'); var codec = { diff --git a/benches/sub_quit_test.js b/benches/sub_quit_test.js index ad1f413228a..ae3725a999c 100644 --- a/benches/sub_quit_test.js +++ b/benches/sub_quit_test.js @@ -1,3 +1,5 @@ +'use strict'; + var client = require("redis").createClient(), client2 = require("redis").createClient(); diff --git a/connection_breaker.js b/connection_breaker.js index 489f5d56450..f2db0eb1b69 100644 --- a/connection_breaker.js +++ b/connection_breaker.js @@ -1,3 +1,5 @@ +'use strict'; + var net = require('net'); var proxyPort = 6379; diff --git a/diff_multi_bench_output.js b/diff_multi_bench_output.js index 73964720198..23cb3ada215 100755 --- a/diff_multi_bench_output.js +++ b/diff_multi_bench_output.js @@ -1,5 +1,7 @@ #!/usr/bin/env node +'use strict'; + var colors = require('colors'), fs = require('fs'), _ = require('underscore'), diff --git a/examples/auth.js b/examples/auth.js index 6c0a563cd8b..275c40961ea 100644 --- a/examples/auth.js +++ b/examples/auth.js @@ -1,3 +1,5 @@ +'use strict'; + var redis = require("redis"), client = redis.createClient(); diff --git a/examples/backpressure_drain.js b/examples/backpressure_drain.js index 3488ef4d3f7..74107bb6a08 100644 --- a/examples/backpressure_drain.js +++ b/examples/backpressure_drain.js @@ -1,3 +1,5 @@ +'use strict'; + var redis = require("../index"), client = redis.createClient(null, null, { command_queue_high_water: 5, diff --git a/examples/eval.js b/examples/eval.js index a3ff6b0793d..0ec1c215e9a 100644 --- a/examples/eval.js +++ b/examples/eval.js @@ -1,3 +1,5 @@ +'use strict'; + var redis = require("../index"), client = redis.createClient(); diff --git a/examples/extend.js b/examples/extend.js index 488b8c2dc5d..b3a10fa7161 100644 --- a/examples/extend.js +++ b/examples/extend.js @@ -1,3 +1,5 @@ +'use strict'; + var redis = require("redis"), client = redis.createClient(); diff --git a/examples/file.js b/examples/file.js index 4d2b5d1c987..91970198585 100644 --- a/examples/file.js +++ b/examples/file.js @@ -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"), diff --git a/examples/mget.js b/examples/mget.js index 936740d32f3..30f2bce90a4 100644 --- a/examples/mget.js +++ b/examples/mget.js @@ -1,3 +1,5 @@ +'use strict'; + var client = require("redis").createClient(); client.mget(["sessions started", "sessions started", "foo"], function (err, res) { diff --git a/examples/monitor.js b/examples/monitor.js index 2cb6a4e1ecb..c67f596294e 100644 --- a/examples/monitor.js +++ b/examples/monitor.js @@ -1,3 +1,5 @@ +'use strict'; + var client = require("../index").createClient(), util = require("util"); diff --git a/examples/multi.js b/examples/multi.js index 35c08e18403..31bc14ffb00 100644 --- a/examples/multi.js +++ b/examples/multi.js @@ -1,3 +1,5 @@ +'use strict'; + var redis = require("redis"), client = redis.createClient(), set_size = 20; diff --git a/examples/multi2.js b/examples/multi2.js index 8be4d7313cc..da722b23bbd 100644 --- a/examples/multi2.js +++ b/examples/multi2.js @@ -1,3 +1,5 @@ +'use strict'; + var redis = require("redis"), client = redis.createClient(), multi; diff --git a/examples/psubscribe.js b/examples/psubscribe.js index c57117b8a63..f46d235bed4 100644 --- a/examples/psubscribe.js +++ b/examples/psubscribe.js @@ -1,3 +1,5 @@ +'use strict'; + var redis = require("redis"), client1 = redis.createClient(), client2 = redis.createClient(), diff --git a/examples/pub_sub.js b/examples/pub_sub.js index aa508d6c9d2..3446a552d16 100644 --- a/examples/pub_sub.js +++ b/examples/pub_sub.js @@ -1,3 +1,5 @@ +'use strict'; + var redis = require("redis"), client1 = redis.createClient(), msg_count = 0, client2 = redis.createClient(); diff --git a/examples/scan.js b/examples/scan.js index 0302843a768..f4aac2ef4d3 100644 --- a/examples/scan.js +++ b/examples/scan.js @@ -1,3 +1,5 @@ +'use strict'; + var redis = require("redis"), client = redis.createClient(); diff --git a/examples/simple.js b/examples/simple.js index f1f2e3209b8..e8327498958 100644 --- a/examples/simple.js +++ b/examples/simple.js @@ -1,3 +1,5 @@ +'use strict'; + var redis = require("redis"), client = redis.createClient(); diff --git a/examples/sort.js b/examples/sort.js index e7c6249e405..4c804bee1db 100644 --- a/examples/sort.js +++ b/examples/sort.js @@ -1,3 +1,5 @@ +'use strict'; + var redis = require("redis"), client = redis.createClient(); diff --git a/examples/subqueries.js b/examples/subqueries.js index 560db2404e1..ebae6d48553 100644 --- a/examples/subqueries.js +++ b/examples/subqueries.js @@ -1,3 +1,5 @@ +'use strict'; + // Sending commands in response to other commands. // This example runs "type" against every key in the database // diff --git a/examples/subquery.js b/examples/subquery.js index 861657e1f3a..4f1edb0ffde 100644 --- a/examples/subquery.js +++ b/examples/subquery.js @@ -1,3 +1,5 @@ +'use strict'; + var client = require("redis").createClient(); function print_results(obj) { diff --git a/examples/web_server.js b/examples/web_server.js index 9fd85923de1..dfd420bd1a3 100644 --- a/examples/web_server.js +++ b/examples/web_server.js @@ -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 }); diff --git a/generate_commands.js b/generate_commands.js index e6949d3a141..3ad420edc35 100644 --- a/generate_commands.js +++ b/generate_commands.js @@ -1,3 +1,5 @@ +'use strict'; + var http = require("http"), fs = require("fs"); diff --git a/index.js b/index.js index 770987beb1e..6c70a251297 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,5 @@ +'use strict'; + /*global Buffer require exports console setTimeout */ var net = require("net"), diff --git a/lib/commands.js b/lib/commands.js index b0365350cda..3b01543d99d 100644 --- a/lib/commands.js +++ b/lib/commands.js @@ -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", diff --git a/lib/parser/hiredis.js b/lib/parser/hiredis.js index 940bfeeb767..29dbfd59a95 100644 --- a/lib/parser/hiredis.js +++ b/lib/parser/hiredis.js @@ -1,3 +1,5 @@ +'use strict'; + var events = require("events"), util = require("../util"), hiredis = require("hiredis"); diff --git a/lib/parser/javascript.js b/lib/parser/javascript.js index 0990cc098da..5ad04362159 100644 --- a/lib/parser/javascript.js +++ b/lib/parser/javascript.js @@ -1,3 +1,5 @@ +'use strict'; + var events = require("events"), util = require("../util"); diff --git a/lib/queue.js b/lib/queue.js index 0d258cdfcbb..d2eb17e56cd 100644 --- a/lib/queue.js +++ b/lib/queue.js @@ -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 diff --git a/lib/to_array.js b/lib/to_array.js index 88a57e18a42..87804f8c3b2 100644 --- a/lib/to_array.js +++ b/lib/to_array.js @@ -1,3 +1,5 @@ +'use strict'; + function to_array(args) { var len = args.length, arr = new Array(len), i; diff --git a/lib/util.js b/lib/util.js index fc255ae9536..359cd7e9481 100644 --- a/lib/util.js +++ b/lib/util.js @@ -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; diff --git a/multi_bench.js b/multi_bench.js index dbe04e515a2..4e99376787e 100644 --- a/multi_bench.js +++ b/multi_bench.js @@ -1,3 +1,5 @@ +'use strict'; + var redis = require("./index"), metrics = require("metrics"), num_clients = parseInt(process.argv[2], 10) || 5, diff --git a/test/queue-test.js b/test/queue-test.js index 017ea60785e..4811eca90ae 100644 --- a/test/queue-test.js +++ b/test/queue-test.js @@ -1,3 +1,5 @@ +'use strict'; + var assert = require("assert"); var Queue = require('../lib/queue'); diff --git a/test/test.js b/test/test.js index e7db7639142..325ea136587 100644 --- a/test/test.js +++ b/test/test.js @@ -1,3 +1,5 @@ +'use strict'; + /*global require console setTimeout process Buffer */ var PORT = 6379; var HOST = '127.0.0.1'; From a2bc59721293bbc9504db06c0ee18a51429c54c6 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Wed, 22 Jul 2015 16:19:02 +0200 Subject: [PATCH 2/6] Add simicolons This is just a style change --- diff_multi_bench_output.js | 2 +- examples/extend.js | 2 +- examples/file.js | 6 +++--- examples/unix_socket.js | 4 +++- index.js | 10 +++++----- test/queue-test.js | 10 +++++----- test/test-unref.js | 16 +++++++++------- test/test.js | 20 ++++++++++---------- 8 files changed, 37 insertions(+), 33 deletions(-) diff --git a/diff_multi_bench_output.js b/diff_multi_bench_output.js index 23cb3ada215..0aff103198c 100755 --- a/diff_multi_bench_output.js +++ b/diff_multi_bench_output.js @@ -49,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); diff --git a/examples/extend.js b/examples/extend.js index b3a10fa7161..22566082d46 100644 --- a/examples/extend.js +++ b/examples/extend.js @@ -16,7 +16,7 @@ redis.RedisClient.prototype.parse_info = function (callback) { obj[parts[0]] = parts[1]; } }); - callback(obj) + callback(obj); }); }; diff --git a/examples/file.js b/examples/file.js index 91970198585..620b0a10550 100644 --- a/examples/file.js +++ b/examples/file.js @@ -13,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) { @@ -23,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."); } diff --git a/examples/unix_socket.js b/examples/unix_socket.js index 4a5e0bb0e84..460b78e857c 100644 --- a/examples/unix_socket.js +++ b/examples/unix_socket.js @@ -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) { diff --git a/index.js b/index.js index 6c70a251297..bdc2889b9a5 100644 --- a/index.js +++ b/index.js @@ -17,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 @@ -141,7 +141,7 @@ RedisClient.prototype.unref = function () { trace("Not connected yet, will unref later"); this.once("connect", function () { this.unref(); - }) + }); } }; @@ -219,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 { @@ -1265,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 = { diff --git a/test/queue-test.js b/test/queue-test.js index 4811eca90ae..dbc9771a0aa 100644 --- a/test/queue-test.js +++ b/test/queue-test.js @@ -11,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) { @@ -24,7 +24,7 @@ module.exports = function (tests, next) { }); return next(); - } + }; tests.forEachWithScope = function () { q.forEach(function (v) { @@ -33,5 +33,5 @@ module.exports = function (tests, next) { }, {foo: 'bar'}); return next(); - } -} + }; +}; diff --git a/test/test-unref.js b/test/test-unref.js index d66d77c4338..c7dc9300047 100644 --- a/test/test-unref.js +++ b/test/test-unref.js @@ -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()); +}); diff --git a/test/test.js b/test/test.js index 325ea136587..7bb2966ff8f 100644 --- a/test/test.js +++ b/test/test.js @@ -137,7 +137,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 +163,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 +189,7 @@ tests.UNIX_SOCKET = function () { console.error("client: " + err.stack); process.exit(); }); -} +}; tests.FLUSHDB = function () { var name = "FLUSHDB"; @@ -1543,7 +1543,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 +2178,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 +2205,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 +2323,9 @@ tests.unref = function () { var external = fork("./test/test-unref.js"); 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 +2336,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(); From 6866ff9b1ef4bc9e677f79a46bd1996d51b52448 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Wed, 22 Jul 2015 16:19:30 +0200 Subject: [PATCH 3/6] Remove trailing whitespace --- benches/buffer_bench.js | 2 +- examples/subquery.js | 2 +- multi_bench.js | 12 ++++++------ 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/benches/buffer_bench.js b/benches/buffer_bench.js index df16d90bf4a..64347e583f0 100644 --- a/benches/buffer_bench.js +++ b/benches/buffer_bench.js @@ -2,7 +2,7 @@ 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; } diff --git a/examples/subquery.js b/examples/subquery.js index 4f1edb0ffde..ffb7eca382e 100644 --- a/examples/subquery.js +++ b/examples/subquery.js @@ -9,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; diff --git a/multi_bench.js b/multi_bench.js index 4e99376787e..9f210a76d4e 100644 --- a/multi_bench.js +++ b/multi_bench.js @@ -25,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; @@ -58,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(); @@ -97,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(); @@ -106,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) { @@ -135,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"); }; From 745fccebfb9e8ac264ad5084944166b493576a91 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Wed, 22 Jul 2015 16:19:46 +0200 Subject: [PATCH 4/6] Add var statements to undeclared variables and remove unused variables --- benches/stress/codec.js | 10 ---------- diff_multi_bench_output.js | 4 ++-- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/benches/stress/codec.js b/benches/stress/codec.js index c679a6ee016..5a3cc6daa4b 100644 --- a/benches/stress/codec.js +++ b/benches/stress/codec.js @@ -5,14 +5,4 @@ var json = { 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; diff --git a/diff_multi_bench_output.js b/diff_multi_bench_output.js index 0aff103198c..8eab0a2c690 100755 --- a/diff_multi_bench_output.js +++ b/diff_multi_bench_output.js @@ -37,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] From 0908e9a46bb1c681410d63fa00da3c9a6b703f43 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Wed, 22 Jul 2015 16:27:05 +0200 Subject: [PATCH 5/6] Use console.log instead of deprecated util.print util.print has been deprecated in node --- test/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test.js b/test/test.js index 7bb2966ff8f..5bcc32fd516 100644 --- a/test/test.js +++ b/test/test.js @@ -2345,7 +2345,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](); From 01a377383bc97522665059ec85b71985d4e2f76e Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Wed, 22 Jul 2015 16:43:01 +0200 Subject: [PATCH 6/6] Use type safe comparison --- diff_multi_bench_output.js | 4 ++-- test/test.js | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/diff_multi_bench_output.js b/diff_multi_bench_output.js index 8eab0a2c690..89b6be479c9 100755 --- a/diff_multi_bench_output.js +++ b/diff_multi_bench_output.js @@ -49,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); @@ -60,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 diff --git a/test/test.js b/test/test.js index 5bcc32fd516..ffb097bda47 100644 --- a/test/test.js +++ b/test/test.js @@ -204,7 +204,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 +371,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 +467,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 +1286,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 {