diff --git a/.gitignore b/.gitignore index f351fac36f..d267c944c0 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ node_modules .tern-port .nyc_output coverage +npm-debug.log diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000000..814239e345 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,24 @@ +{ + "eqeqeq": true, // Prohibits the use of == and != in favor of === and !== + "noarg": true, // Prohibit use of `arguments.caller` and `arguments.callee` + "undef": true, // Require all non-global variables be declared before they are used. + "unused": "vars", // Warn unused variables, but not unused params + "strict": true, // Require `use strict` pragma in every file. + "nonbsp": true, // don't allow non utf-8 pages to break + "forin": true, // don't allow not filtert for in loops + "freeze": true, // prohibit overwriting prototypes of native objects + "nonew": true, // prohibit use of constructors with new when not assigning to a variable + "maxdepth": 6, + "latedef": true, + "maxparams": 5, + + // Environment options + "node": true, // Enable globals available when code is running inside of the NodeJS runtime environment. + "mocha": true, + + "overrides": { + "examples/*.js": { + "unused": false + } + } +} diff --git a/benches/re_sub_test.js b/benches/re_sub_test.js index 256d0d0d1d..62c9302f90 100644 --- a/benches/re_sub_test.js +++ b/benches/re_sub_test.js @@ -1,8 +1,7 @@ 'use strict'; -var client = require('../index').createClient() - , client2 = require('../index').createClient() - , assert = require('assert'); +var client = require('../index').createClient(); +var client2 = require('../index').createClient(); client.once('subscribe', function (channel, count) { client.unsubscribe('x'); diff --git a/benches/stress/pubsub/pub.js b/benches/stress/pubsub/pub.js index 0acde7a6eb..51c6555f83 100644 --- a/benches/stress/pubsub/pub.js +++ b/benches/stress/pubsub/pub.js @@ -3,8 +3,8 @@ var freemem = require('os').freemem; var profiler = require('v8-profiler'); var codec = require('../codec'); - var sent = 0; +var exec; var pub = require('redis').createClient(null, null, { //command_queue_high_water: 5, diff --git a/benches/stress/pubsub/server.js b/benches/stress/pubsub/server.js index 035e6b7440..0679561b1d 100644 --- a/benches/stress/pubsub/server.js +++ b/benches/stress/pubsub/server.js @@ -6,12 +6,11 @@ var codec = require('../codec'); var id = Math.random(); var recv = 0; -var sub = require('redis').createClient() +require('redis').createClient() .on('ready', function() { this.subscribe('timeline'); }) .on('message', function(channel, message) { - var self = this; if (message) { message = codec.decode(message); ++recv; diff --git a/benches/stress/rpushblpop/pub.js b/benches/stress/rpushblpop/pub.js index 9caf1d0b82..009407857d 100644 --- a/benches/stress/rpushblpop/pub.js +++ b/benches/stress/rpushblpop/pub.js @@ -6,6 +6,8 @@ var codec = require('../codec'); var sent = 0; +var exec; + var pub = require('redis').createClient(null, null, { //command_queue_high_water: 5, //command_queue_low_water: 1 diff --git a/benches/stress/rpushblpop/server.js b/benches/stress/rpushblpop/server.js index 9cbcdd9ed7..7a18a9b3f5 100644 --- a/benches/stress/rpushblpop/server.js +++ b/benches/stress/rpushblpop/server.js @@ -7,7 +7,8 @@ var id = Math.random(); var recv = 0; var cmd = require('redis').createClient(); -var sub = require('redis').createClient() + +require('redis').createClient() .on('ready', function() { this.emit('timeline'); }) diff --git a/benches/stress/speed/speed.js b/benches/stress/speed/speed.js index 93d54f0c13..7b76db6f4c 100644 --- a/benches/stress/speed/speed.js +++ b/benches/stress/speed/speed.js @@ -16,6 +16,40 @@ var codec = { var obj, l; +function run(obj, codec) { + var t1 = Date.now(); + var n = 10000; + for (var i = 0; i < n; ++i) { + codec.decode(l = codec.encode(obj)); + } + var t2 = Date.now(); + //console.log('DONE', n*1000/(t2-t1), 'codecs/sec, length=', l.length); + return [n*1000/(t2-t1), l.length]; +} + +function series(obj, cname, n) { + var rate = 0; + var len = 0; + for (var i = 0; i < n; ++i) { + var r = run(obj, codec[cname]); + rate += r[0]; + len += r[1]; + } + rate /= n; + len /= n; + console.log(cname + ' ' + rate + ' ' + len); + return [rate, len]; +} + +function forObj(obj) { + var r = { + JSON: series(obj, 'JSON', 20), + msgpack: series(obj, 'msgpack', 20), + bison: series(obj, 'bison', 20) + }; + return r; +} + var s = '0'; for (var i = 0; i < 12; ++i) s += s; @@ -50,37 +84,3 @@ obj = { rand: [] }; forObj(obj); - -function run(obj, codec) { - var t1 = Date.now(); - var n = 10000; - for (var i = 0; i < n; ++i) { - codec.decode(l = codec.encode(obj)); - } - var t2 = Date.now(); - //console.log('DONE', n*1000/(t2-t1), 'codecs/sec, length=', l.length); - return [n*1000/(t2-t1), l.length]; -} - -function series(obj, cname, n) { - var rate = 0; - var len = 0; - for (var i = 0; i < n; ++i) { - var r = run(obj, codec[cname]); - rate += r[0]; - len += r[1]; - } - rate /= n; - len /= n; - console.log(cname + ' ' + rate + ' ' + len); - return [rate, len]; -} - -function forObj(obj) { - var r = { - JSON: series(obj, 'JSON', 20), - msgpack: series(obj, 'msgpack', 20), - bison: series(obj, 'bison', 20) - }; - return r; -} diff --git a/connection_breaker.js b/connection_breaker.js index f2db0eb1b6..e036a2b173 100644 --- a/connection_breaker.js +++ b/connection_breaker.js @@ -42,8 +42,6 @@ server.listen(6479); var redis = require('./'); -var port = 6479; - var client = redis.createClient(6479, 'localhost'); function iter() { diff --git a/diff_multi_bench_output.js b/diff_multi_bench_output.js index 89b6be479c..86a9414d04 100755 --- a/diff_multi_bench_output.js +++ b/diff_multi_bench_output.js @@ -2,9 +2,9 @@ 'use strict'; -var colors = require('colors'), - fs = require('fs'), - _ = require('underscore'), +/* jshint -W079: Ignore redefinitions (before & after) */ + +var fs = require('fs'), metrics = require('metrics'), // `node diff_multi_bench_output.js before.txt after.txt` @@ -30,6 +30,28 @@ console.log('Comparing before,', before.green, '(', before_lines.length, var total_ops = new metrics.Histogram.createUniformHistogram(); +function is_whitespace(s) { + return !!s.trim(); +} + +function parseInt10(s) { + return parseInt(s, 10); +} + +// green if greater than 0, red otherwise +function humanize_diff(num, unit) { + unit = unit || ""; + if (num > 0) { + return ('+' + num + unit).green; + } + return ('' + num + unit).red; +} + +function command_name(words) { + var line = words.join(' '); + return line.substr(0, line.indexOf(',')); +} + before_lines.forEach(function(b, i) { var a = after_lines[i]; if (!a || !b || !b.trim() || !a.trim()) { @@ -60,33 +82,11 @@ 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) + ':' - : '404:', + command_name(a_words) === command_name(b_words) ? + command_name(a_words) + ':' : + '404:', // results of test ops.join(' -> '), 'ops/sec (∆', delta, pct, ')'); }); console.log('Mean difference in ops/sec:', humanize_diff(total_ops.mean().toPrecision(6))); - -function is_whitespace(s) { - return !!s.trim(); -} - -function parseInt10(s) { - return parseInt(s, 10); -} - -// green if greater than 0, red otherwise -function humanize_diff(num, unit) { - unit = unit || ""; - if (num > 0) { - return ('+' + num + unit).green; - } - return ('' + num + unit).red; -} - -function command_name(words) { - var line = words.join(' '); - return line.substr(0, line.indexOf(',')); -} diff --git a/examples/unix_socket.js b/examples/unix_socket.js index 460b78e857..a6c74cbc3e 100644 --- a/examples/unix_socket.js +++ b/examples/unix_socket.js @@ -27,5 +27,5 @@ function done() { setTimeout(function () { console.log("Taking snapshot."); - var snap = profiler.takeSnapshot(); + profiler.takeSnapshot(); }, 5000); diff --git a/index.js b/index.js index ef53de50ce..2466130d8f 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,5 @@ 'use strict'; -/*global Buffer require exports console setTimeout */ - var net = require("net"), URL = require("url"), util = require("util"), @@ -616,7 +614,7 @@ RedisClient.prototype.return_reply = function (reply) { type = reply[0].toString(); } - if (this.pub_sub_mode && (type == 'message' || type == 'pmessage')) { + if (this.pub_sub_mode && (type === 'message' || type === 'pmessage')) { debug("received pubsub message"); } else { @@ -1172,30 +1170,6 @@ RedisClient.prototype.eval = RedisClient.prototype.EVAL = function () { }); }; -exports.createClient = function(port_arg, host_arg, options) { - if (typeof port_arg === 'object' || port_arg === undefined) { - options = port_arg || options; - return createClient_tcp(default_port, default_host, options); - } - if (typeof port_arg === 'number' || typeof port_arg === 'string' && /^\d+$/.test(port_arg)) { - return createClient_tcp(port_arg, host_arg, options); - } - if (typeof port_arg === 'string') { - options = host_arg || {}; - - var parsed = URL.parse(port_arg, true, true); - if (parsed.hostname) { - if (parsed.auth) { - options.auth_pass = parsed.auth.split(':')[1]; - } - return createClient_tcp(parsed.port, parsed.hostname, options); - } - - return createClient_unix(port_arg, options); - } - throw new Error('unknown type of connection in createClient()'); -}; - var createClient_unix = function(path, options){ var cnxOptions = { path: path @@ -1224,6 +1198,30 @@ var createClient_tcp = function (port_arg, host_arg, options) { return redis_client; }; +exports.createClient = function(port_arg, host_arg, options) { + if (typeof port_arg === 'object' || port_arg === undefined) { + options = port_arg || options; + return createClient_tcp(default_port, default_host, options); + } + if (typeof port_arg === 'number' || typeof port_arg === 'string' && /^\d+$/.test(port_arg)) { + return createClient_tcp(port_arg, host_arg, options); + } + if (typeof port_arg === 'string') { + options = host_arg || {}; + + var parsed = URL.parse(port_arg, true, true); + if (parsed.hostname) { + if (parsed.auth) { + options.auth_pass = parsed.auth.split(':')[1]; + } + return createClient_tcp(parsed.port, parsed.hostname, options); + } + + return createClient_unix(port_arg, options); + } + throw new Error('unknown type of connection in createClient()'); +}; + exports.print = function (err, reply) { if (err) { console.log("Error: " + err); diff --git a/package.json b/package.json index 6e322a046a..f6bbc41e73 100644 --- a/package.json +++ b/package.json @@ -11,13 +11,15 @@ "main": "./index.js", "scripts": { "coverage": "nyc report --reporter=text-lcov | coveralls", - "test": "nyc ./node_modules/.bin/_mocha ./test/*.js ./test/commands/*.js ./test/parser/*.js --timeout=8000" + "test": "nyc ./node_modules/.bin/_mocha ./test/*.js ./test/commands/*.js ./test/parser/*.js --timeout=8000", + "jshint": "./node_modules/.bin/jshint *.js **/*.js **/**/*.js --exclude=node_modules/**/*" }, "devDependencies": { "async": "^1.3.0", "colors": "~0.6.0-1", "coveralls": "^2.11.2", "hiredis": "^0.4.1", + "jshint": "^2.8.0", "metrics": ">=0.1.5", "mocha": "^2.2.5", "nyc": "^3.0.0", diff --git a/test/auth.spec.js b/test/auth.spec.js index 63ce1cf9ff..5dee3d83a3 100644 --- a/test/auth.spec.js +++ b/test/auth.spec.js @@ -1,7 +1,8 @@ +'use strict'; + var assert = require("assert"); var config = require("./lib/config"); -var helper = require('./helper') -var path = require('path'); +var helper = require('./helper'); var redis = config.redis; describe("client authentication", function () { diff --git a/test/commands/blpop.spec.js b/test/commands/blpop.spec.js index e547415438..843b351dc8 100644 --- a/test/commands/blpop.spec.js +++ b/test/commands/blpop.spec.js @@ -1,3 +1,5 @@ +'use strict'; + var assert = require("assert"); var config = require("../lib/config"); var helper = require("../helper"); diff --git a/test/commands/client.spec.js b/test/commands/client.spec.js index d0ae072f9f..a9188cdac9 100644 --- a/test/commands/client.spec.js +++ b/test/commands/client.spec.js @@ -1,3 +1,5 @@ +'use strict'; + var assert = require("assert"); var config = require("../lib/config"); var helper = require("../helper"); diff --git a/test/commands/dbsize.spec.js b/test/commands/dbsize.spec.js index d65e9469b2..5eb6958e9c 100644 --- a/test/commands/dbsize.spec.js +++ b/test/commands/dbsize.spec.js @@ -1,4 +1,5 @@ -var async = require('async'); +'use strict'; + var assert = require('assert'); var config = require("../lib/config"); var helper = require('../helper'); diff --git a/test/commands/del.spec.js b/test/commands/del.spec.js index 6845ee363f..8a110485c6 100644 --- a/test/commands/del.spec.js +++ b/test/commands/del.spec.js @@ -1,4 +1,5 @@ -var assert = require("assert"); +'use strict'; + var config = require("../lib/config"); var helper = require("../helper"); var redis = config.redis; diff --git a/test/commands/eval.spec.js b/test/commands/eval.spec.js index d132e7c2a9..229e9c51b0 100644 --- a/test/commands/eval.spec.js +++ b/test/commands/eval.spec.js @@ -1,3 +1,5 @@ +'use strict'; + var assert = require("assert"); var config = require("../lib/config"); var crypto = require("crypto"); diff --git a/test/commands/exits.spec.js b/test/commands/exits.spec.js index c36e9bcfed..2fd2ac5fce 100644 --- a/test/commands/exits.spec.js +++ b/test/commands/exits.spec.js @@ -1,4 +1,5 @@ -var assert = require("assert"); +'use strict'; + var config = require("../lib/config"); var helper = require("../helper"); var redis = config.redis; diff --git a/test/commands/expire.spec.js b/test/commands/expire.spec.js index 8e7d3a188e..ce3af95dc2 100644 --- a/test/commands/expire.spec.js +++ b/test/commands/expire.spec.js @@ -1,4 +1,5 @@ -var assert = require("assert"); +'use strict'; + var config = require("../lib/config"); var helper = require("../helper"); var redis = config.redis; diff --git a/test/commands/flushdb.spec.js b/test/commands/flushdb.spec.js index 80533d3462..c8e70bf58f 100644 --- a/test/commands/flushdb.spec.js +++ b/test/commands/flushdb.spec.js @@ -1,3 +1,5 @@ +'use strict'; + var async = require('async'); var assert = require('assert'); var config = require("../lib/config"); diff --git a/test/commands/get.spec.js b/test/commands/get.spec.js index 4ba2621f0f..3d3fd1e248 100644 --- a/test/commands/get.spec.js +++ b/test/commands/get.spec.js @@ -1,4 +1,5 @@ -var async = require('async'); +'use strict'; + var assert = require('assert'); var config = require("../lib/config"); var helper = require('../helper'); diff --git a/test/commands/getset.spec.js b/test/commands/getset.spec.js index f3c294a669..a47cd2d0b5 100644 --- a/test/commands/getset.spec.js +++ b/test/commands/getset.spec.js @@ -1,4 +1,5 @@ -var async = require('async'); +'use strict'; + var assert = require('assert'); var config = require("../lib/config"); var helper = require('../helper'); diff --git a/test/commands/hgetall.spec.js b/test/commands/hgetall.spec.js index aa3e520ceb..0735bf31de 100644 --- a/test/commands/hgetall.spec.js +++ b/test/commands/hgetall.spec.js @@ -1,3 +1,5 @@ +'use strict'; + var assert = require("assert"); var config = require("../lib/config"); var helper = require("../helper"); diff --git a/test/commands/hincrby.spec.js b/test/commands/hincrby.spec.js index b1da736027..c8a7cfc93e 100644 --- a/test/commands/hincrby.spec.js +++ b/test/commands/hincrby.spec.js @@ -1,4 +1,5 @@ -var assert = require("assert"); +'use strict'; + var config = require("../lib/config"); var helper = require("../helper"); var redis = config.redis; diff --git a/test/commands/hlen.spec.js b/test/commands/hlen.spec.js index 7756e3366b..564f248ed5 100644 --- a/test/commands/hlen.spec.js +++ b/test/commands/hlen.spec.js @@ -1,4 +1,5 @@ -var assert = require("assert"); +'use strict'; + var config = require("../lib/config"); var helper = require("../helper"); var redis = config.redis; diff --git a/test/commands/hmget.spec.js b/test/commands/hmget.spec.js index 6ab175a914..1b5387dc32 100644 --- a/test/commands/hmget.spec.js +++ b/test/commands/hmget.spec.js @@ -1,3 +1,5 @@ +'use strict'; + var assert = require("assert"); var config = require("../lib/config"); var helper = require("../helper"); diff --git a/test/commands/hmset.spec.js b/test/commands/hmset.spec.js index 88b9827286..6b6f980aa9 100644 --- a/test/commands/hmset.spec.js +++ b/test/commands/hmset.spec.js @@ -1,3 +1,5 @@ +'use strict'; + var assert = require("assert"); var config = require("../lib/config"); var helper = require("../helper"); @@ -58,7 +60,7 @@ describe("The 'hmset' method", function () { client.HMSET(hash, 99, 'banana', 'test', 25); client.HGETALL(hash, function (err, obj) { assert.equal(obj['99'], 'banana'); - assert.equal(obj['test'], '25'); + assert.equal(obj.test, '25'); return done(err); }); }); @@ -67,7 +69,7 @@ describe("The 'hmset' method", function () { client.HMSET([hash, 99, 'banana', 'test', 25]); client.HGETALL(hash, function (err, obj) { assert.equal(obj['99'], 'banana'); - assert.equal(obj['test'], '25'); + assert.equal(obj.test, '25'); return done(err); }); }); @@ -76,7 +78,7 @@ describe("The 'hmset' method", function () { client.HMSET([hash, 99, 'banana', 'test', 25], helper.isString('OK')); client.HGETALL(hash, function (err, obj) { assert.equal(obj['99'], 'banana'); - assert.equal(obj['test'], '25'); + assert.equal(obj.test, '25'); return done(err); }); }); @@ -87,7 +89,7 @@ describe("The 'hmset' method", function () { assert.equal(obj['0123456789'], 'abcdefghij'); assert.equal(obj['some manner of key'], 'a type of value'); return done(err); - }) + }); }); afterEach(function () { diff --git a/test/commands/hset.spec.js b/test/commands/hset.spec.js index 668838b60d..9f55606f35 100644 --- a/test/commands/hset.spec.js +++ b/test/commands/hset.spec.js @@ -1,3 +1,5 @@ +'use strict'; + var assert = require("assert"); var config = require("../lib/config"); var helper = require("../helper"); diff --git a/test/commands/incr.spec.js b/test/commands/incr.spec.js index 4e06427933..bc303da651 100644 --- a/test/commands/incr.spec.js +++ b/test/commands/incr.spec.js @@ -1,9 +1,9 @@ -var async = require('async'); +'use strict'; + var assert = require('assert'); var config = require("../lib/config"); var helper = require('../helper'); var redis = config.redis; -var uuid = require('uuid'); describe("The 'incr' method", function () { diff --git a/test/commands/keys.spec.js b/test/commands/keys.spec.js index 07add24650..aaf6ddadf4 100644 --- a/test/commands/keys.spec.js +++ b/test/commands/keys.spec.js @@ -1,3 +1,5 @@ +'use strict'; + var assert = require("assert"); var config = require("../lib/config"); var crypto = require("crypto"); diff --git a/test/commands/mget.spec.js b/test/commands/mget.spec.js index c4052a17fd..270ff37854 100644 --- a/test/commands/mget.spec.js +++ b/test/commands/mget.spec.js @@ -1,3 +1,5 @@ +'use strict'; + var assert = require("assert"); var config = require("../lib/config"); var helper = require("../helper"); diff --git a/test/commands/mset.spec.js b/test/commands/mset.spec.js index 45dab25462..950e6870a6 100644 --- a/test/commands/mset.spec.js +++ b/test/commands/mset.spec.js @@ -1,4 +1,5 @@ -var async = require('async'); +'use strict'; + var assert = require('assert'); var config = require("../lib/config"); var helper = require('../helper'); diff --git a/test/commands/msetnx.spec.js b/test/commands/msetnx.spec.js index ef7cf63e9f..8084677839 100644 --- a/test/commands/msetnx.spec.js +++ b/test/commands/msetnx.spec.js @@ -1,4 +1,5 @@ -var assert = require("assert"); +'use strict'; + var config = require("../lib/config"); var helper = require("../helper"); var redis = config.redis; diff --git a/test/commands/multi.spec.js b/test/commands/multi.spec.js index f99e85211f..651389e6ce 100644 --- a/test/commands/multi.spec.js +++ b/test/commands/multi.spec.js @@ -1,4 +1,5 @@ -var async = require('async'); +'use strict'; + var assert = require('assert'); var config = require("../lib/config"); var helper = require('../helper'); @@ -58,7 +59,7 @@ describe("The 'multi' method", function () { }); it('roles back a transaction when one command in a sequence of commands fails', function (done) { - var name = "MULTI_1", multi1, multi2; + var multi1, multi2; // Provoke an error at queue time multi1 = client.multi(); @@ -91,7 +92,7 @@ describe("The 'multi' method", function () { // I'm unclear as to the difference between this test in the test above, // perhaps @mranney can clarify? it('roles back a transaction when an error was provoked at queue time', function (done) { - multi1 = client.multi(); + var multi1 = client.multi(); multi1.mset("multifoo_8", "10", "multibar_8", "20", helper.isString("OK")); multi1.set("foo2", helper.isError()); multi1.set("foo3", helper.isError()); @@ -108,7 +109,7 @@ describe("The 'multi' method", function () { } // Confirm that the previous command, while containing an error, still worked. - multi2 = client.multi(); + var multi2 = client.multi(); multi2.incr("multibar_8", helper.isNumber(multibar_expected)); multi2.incr("multifoo_8", helper.isNumber(multifoo_expected)); multi2.exec(function (err, replies) { diff --git a/test/commands/randomkey.test.js b/test/commands/randomkey.test.js index ef11253adb..4c81ed2edb 100644 --- a/test/commands/randomkey.test.js +++ b/test/commands/randomkey.test.js @@ -1,3 +1,5 @@ +'use strict'; + var assert = require("assert"); var config = require("../lib/config"); var helper = require("../helper"); diff --git a/test/commands/rename.spec.js b/test/commands/rename.spec.js index 3389fa59da..6196994c58 100644 --- a/test/commands/rename.spec.js +++ b/test/commands/rename.spec.js @@ -1,4 +1,5 @@ -var assert = require("assert"); +'use strict'; + var config = require("../lib/config"); var helper = require("../helper"); var redis = config.redis; diff --git a/test/commands/renamenx.spec.js b/test/commands/renamenx.spec.js index 233d1aaba5..57eb6dab07 100644 --- a/test/commands/renamenx.spec.js +++ b/test/commands/renamenx.spec.js @@ -1,4 +1,5 @@ -var assert = require("assert"); +'use strict'; + var config = require("../lib/config"); var helper = require("../helper"); var redis = config.redis; diff --git a/test/commands/sadd.spec.js b/test/commands/sadd.spec.js index a6a8ac4330..1761cd6cf3 100644 --- a/test/commands/sadd.spec.js +++ b/test/commands/sadd.spec.js @@ -1,3 +1,5 @@ +'use strict'; + var assert = require("assert"); var config = require("../lib/config"); var helper = require("../helper"); diff --git a/test/commands/scard.spec.js b/test/commands/scard.spec.js index 180da0a98e..423cba9805 100644 --- a/test/commands/scard.spec.js +++ b/test/commands/scard.spec.js @@ -1,4 +1,5 @@ -var assert = require("assert"); +'use strict'; + var config = require("../lib/config"); var helper = require("../helper"); var redis = config.redis; diff --git a/test/commands/script.spec.js b/test/commands/script.spec.js index 80cbf1abc0..507c0befb3 100644 --- a/test/commands/script.spec.js +++ b/test/commands/script.spec.js @@ -1,3 +1,5 @@ +'use strict'; + var assert = require("assert"); var config = require("../lib/config"); var crypto = require("crypto"); diff --git a/test/commands/sdiff.spec.js b/test/commands/sdiff.spec.js index 0e233f26ff..8057bc15af 100644 --- a/test/commands/sdiff.spec.js +++ b/test/commands/sdiff.spec.js @@ -1,3 +1,5 @@ +'use strict'; + var assert = require("assert"); var config = require("../lib/config"); var helper = require("../helper"); diff --git a/test/commands/sdiffstore.spec.js b/test/commands/sdiffstore.spec.js index c497cf47e2..7546c446ce 100644 --- a/test/commands/sdiffstore.spec.js +++ b/test/commands/sdiffstore.spec.js @@ -1,3 +1,5 @@ +'use strict'; + var assert = require("assert"); var config = require("../lib/config"); var helper = require("../helper"); diff --git a/test/commands/select.spec.js b/test/commands/select.spec.js index f12eb07d97..25f45f5d53 100644 --- a/test/commands/select.spec.js +++ b/test/commands/select.spec.js @@ -1,4 +1,5 @@ -var async = require('async'); +'use strict'; + var assert = require('assert'); var config = require("../lib/config"); var helper = require('../helper'); diff --git a/test/commands/set.spec.js b/test/commands/set.spec.js index 072342db4b..a6e49d0ab3 100644 --- a/test/commands/set.spec.js +++ b/test/commands/set.spec.js @@ -1,4 +1,5 @@ -var async = require('async'); +'use strict'; + var assert = require('assert'); var config = require("../lib/config"); var helper = require('../helper'); diff --git a/test/commands/setex.spec.js b/test/commands/setex.spec.js index b4e6189168..71e55b20e7 100644 --- a/test/commands/setex.spec.js +++ b/test/commands/setex.spec.js @@ -1,3 +1,5 @@ +'use strict'; + var assert = require("assert"); var config = require("../lib/config"); var helper = require("../helper"); diff --git a/test/commands/setnx.spec.js b/test/commands/setnx.spec.js index 9b363a32fd..20a5759305 100644 --- a/test/commands/setnx.spec.js +++ b/test/commands/setnx.spec.js @@ -1,4 +1,5 @@ -var assert = require("assert"); +'use strict'; + var config = require("../lib/config"); var helper = require("../helper"); var redis = config.redis; diff --git a/test/commands/sinter.spec.js b/test/commands/sinter.spec.js index 6bc87390bb..59b751fb5f 100644 --- a/test/commands/sinter.spec.js +++ b/test/commands/sinter.spec.js @@ -1,3 +1,5 @@ +'use strict'; + var assert = require("assert"); var config = require("../lib/config"); var helper = require("../helper"); diff --git a/test/commands/sinterstore.spec.js b/test/commands/sinterstore.spec.js index 7cf783bf25..38a9ffc39b 100644 --- a/test/commands/sinterstore.spec.js +++ b/test/commands/sinterstore.spec.js @@ -1,3 +1,5 @@ +'use strict'; + var assert = require("assert"); var config = require("../lib/config"); var helper = require("../helper"); diff --git a/test/commands/sismember.spec.js b/test/commands/sismember.spec.js index fdc00da1da..1e1d29e5af 100644 --- a/test/commands/sismember.spec.js +++ b/test/commands/sismember.spec.js @@ -1,4 +1,5 @@ -var assert = require("assert"); +'use strict'; + var config = require("../lib/config"); var helper = require("../helper"); var redis = config.redis; diff --git a/test/commands/slowlog.spec.js b/test/commands/slowlog.spec.js index b2d304911b..c64b0ebf58 100644 --- a/test/commands/slowlog.spec.js +++ b/test/commands/slowlog.spec.js @@ -1,3 +1,5 @@ +'use strict'; + var assert = require("assert"); var config = require("../lib/config"); var helper = require("../helper"); diff --git a/test/commands/smembers.spec.js b/test/commands/smembers.spec.js index 39bca826bc..acca8f899d 100644 --- a/test/commands/smembers.spec.js +++ b/test/commands/smembers.spec.js @@ -1,3 +1,5 @@ +'use strict'; + var assert = require("assert"); var config = require("../lib/config"); var helper = require("../helper"); diff --git a/test/commands/smove.spec.js b/test/commands/smove.spec.js index d9ad3c4021..abdc2e476a 100644 --- a/test/commands/smove.spec.js +++ b/test/commands/smove.spec.js @@ -1,4 +1,5 @@ -var assert = require("assert"); +'use strict'; + var config = require("../lib/config"); var helper = require("../helper"); var redis = config.redis; diff --git a/test/commands/sort.spec.js b/test/commands/sort.spec.js index c38dfd4685..868d26a7f2 100644 --- a/test/commands/sort.spec.js +++ b/test/commands/sort.spec.js @@ -1,3 +1,5 @@ +'use strict'; + var assert = require("assert"); var config = require("../lib/config"); var helper = require("../helper"); diff --git a/test/commands/spop.spec.js b/test/commands/spop.spec.js index 75470d5562..0beb4869a1 100644 --- a/test/commands/spop.spec.js +++ b/test/commands/spop.spec.js @@ -1,3 +1,5 @@ +'use strict'; + var assert = require("assert"); var config = require("../lib/config"); var helper = require("../helper"); diff --git a/test/commands/srem.spec.js b/test/commands/srem.spec.js index af456abf10..a62dd6bc83 100644 --- a/test/commands/srem.spec.js +++ b/test/commands/srem.spec.js @@ -1,3 +1,5 @@ +'use strict'; + var assert = require("assert"); var config = require("../lib/config"); var helper = require("../helper"); diff --git a/test/commands/sunion.spec.js b/test/commands/sunion.spec.js index bf61c5e680..2477526d0b 100644 --- a/test/commands/sunion.spec.js +++ b/test/commands/sunion.spec.js @@ -1,3 +1,5 @@ +'use strict'; + var assert = require("assert"); var config = require("../lib/config"); var helper = require("../helper"); diff --git a/test/commands/sunionstore.spec.js b/test/commands/sunionstore.spec.js index 644bb8744b..a4086de6a3 100644 --- a/test/commands/sunionstore.spec.js +++ b/test/commands/sunionstore.spec.js @@ -1,3 +1,5 @@ +'use strict'; + var assert = require("assert"); var config = require("../lib/config"); var helper = require("../helper"); diff --git a/test/commands/ttl.spec.js b/test/commands/ttl.spec.js index c8988ab05b..35beaa6baf 100644 --- a/test/commands/ttl.spec.js +++ b/test/commands/ttl.spec.js @@ -1,3 +1,5 @@ +'use strict'; + var assert = require("assert"); var config = require("../lib/config"); var helper = require("../helper"); diff --git a/test/commands/type.spec.js b/test/commands/type.spec.js index 5c438bbd17..1410b325de 100644 --- a/test/commands/type.spec.js +++ b/test/commands/type.spec.js @@ -1,4 +1,5 @@ -var assert = require("assert"); +'use strict'; + var config = require("../lib/config"); var helper = require("../helper"); var redis = config.redis; diff --git a/test/commands/watch.spec.js b/test/commands/watch.spec.js index a4abdce877..355f31b9b9 100644 --- a/test/commands/watch.spec.js +++ b/test/commands/watch.spec.js @@ -1,3 +1,5 @@ +'use strict'; + var assert = require("assert"); var config = require("../lib/config"); var helper = require("../helper"); @@ -33,7 +35,7 @@ describe("The 'watch' method", function () { it('does not execute transaction if watched key was modified prior to execution', function (done) { client.watch(watched); client.incr(watched); - multi = client.multi(); + var multi = client.multi(); multi.incr(watched); multi.exec(helper.isNull(done)); }) @@ -45,17 +47,15 @@ describe("The 'watch' method", function () { client.watch(watched); client.incr(watched); - var multi = client.multi() - .incr(watched) - .exec(function (err, replies) { - assert.strictEqual(replies, null, "Aborted transaction multi-bulk reply should be null."); + client.multi().incr(watched).exec(function (err, replies) { + assert.strictEqual(replies, null, "Aborted transaction multi-bulk reply should be null."); - client.get("unwatched", function (err, reply) { - assert.equal(reply, 200, "Expected 200, got " + reply); - return done(err) - }); - }); - }) + client.get("unwatched", function (err, reply) { + assert.equal(reply, 200, "Expected 200, got " + reply); + return done(err); + }); + }); + }); }); }); }); diff --git a/test/helper.js b/test/helper.js index 756ed1d139..30fc7b24e8 100644 --- a/test/helper.js +++ b/test/helper.js @@ -1,9 +1,18 @@ +'use strict'; + var assert = require("assert"); var path = require('path'); var config = require("./lib/config"); var RedisProcess = require("./lib/redis-process"); var rp; +function startRedis (conf, done) { + RedisProcess.start(function (err, _rp) { + rp = _rp; + return done(err); + }, path.resolve(__dirname, conf)); +} + // don't start redis every time we // include this helper file! if (!process.env.REDIS_TESTS_STARTED) { @@ -108,11 +117,4 @@ module.exports = { process.removeListener('uncaughtException', mochaListener); return mochaListener; } -} - -function startRedis (conf, done) { - RedisProcess.start(function (err, _rp) { - rp = _rp; - return done(err); - }, path.resolve(__dirname, conf)); -} +}; diff --git a/test/lib/config.js b/test/lib/config.js index 296fdc0bf8..c80a8f9420 100644 --- a/test/lib/config.js +++ b/test/lib/config.js @@ -1,3 +1,5 @@ +'use strict'; + // helpers for configuring a redis client in // its various modes, ipV6, ipV4, socket. var redis = require('../../index'); diff --git a/test/lib/redis-process.js b/test/lib/redis-process.js index 32f2045e41..fbf176d592 100644 --- a/test/lib/redis-process.js +++ b/test/lib/redis-process.js @@ -1,3 +1,5 @@ +'use strict'; + // helper to start and stop the redis process. var cp = require('child_process'); var config = require('./config'); @@ -5,6 +7,26 @@ var fs = require('fs'); var path = require('path'); var tcpPortUsed = require('tcp-port-used'); +// wait for redis to be listening in +// all three modes (ipv4, ipv6, socket). +function waitForRedis (available, cb) { + var ipV4 = false; + var id = setInterval(function () { + tcpPortUsed.check(config.PORT, '127.0.0.1') + .then(function (_ipV4) { + ipV4 = _ipV4; + return tcpPortUsed.check(config.PORT, '::1'); + }) + .then(function (ipV6) { + if (ipV6 === available && ipV4 === available && + fs.existsSync('/tmp/redis.sock') === available) { + clearInterval(id); + return cb(); + } + }); + }, 100); +} + module.exports = { start: function (done, conf) { // spawn redis with our testing configuration. @@ -18,9 +40,9 @@ module.exports = { console.error('failed to starting redis with exit code "' + code + '" ' + 'stop any other redis processes currently running (' + 'hint: lsof -i :6379)'); - process.exit(code) + process.exit(code); } - }) + }); // wait for redis to become available, by // checking the port we bind on. @@ -44,23 +66,3 @@ module.exports = { }); } }; - -// wait for redis to be listening in -// all three modes (ipv4, ipv6, socket). -function waitForRedis (available, cb) { - var ipV4 = false; - var id = setInterval(function () { - tcpPortUsed.check(config.PORT, '127.0.0.1') - .then(function (_ipV4) { - ipV4 = _ipV4; - return tcpPortUsed.check(config.PORT, '::1'); - }) - .then(function (ipV6) { - if (ipV6 === available && ipV4 === available && - fs.existsSync('/tmp/redis.sock') === available) { - clearInterval(id); - return cb(); - } - }); - }, 100); -} diff --git a/test/node_redis.spec.js b/test/node_redis.spec.js index 93b5531473..999b11f404 100644 --- a/test/node_redis.spec.js +++ b/test/node_redis.spec.js @@ -1,3 +1,5 @@ +'use strict'; + var async = require("async"); var assert = require("assert"); var config = require("./lib/config"); @@ -249,7 +251,7 @@ describe("The node_redis client", function () { try { domain = require('domain').create(); } catch (err) { - console.log("Skipping " + name + " because this version of node doesn't have domains."); + console.log("Skipping test because this version of node doesn't have domains."); return done(); } @@ -257,7 +259,7 @@ describe("The node_redis client", function () { domain.run(function () { client.set('domain', 'value', function (err, res) { assert.ok(process.domain); - var notFound = res.not.existing.thing; // ohhh nooooo + throw new Error('ohhhh noooo'); }); }); @@ -316,7 +318,7 @@ describe("The node_redis client", function () { }); client2.on("message", function (channel, data) { - if (channel == name) { + if (channel === name) { assert.equal(data, "some message"); throw Error('forced exception'); } @@ -736,7 +738,7 @@ describe("The node_redis client", function () { }); assert.throws(function () { - cli.set('foo', 'bar'); + client.set('foo', 'bar'); }); assert.doesNotThrow(function () { diff --git a/test/parser/javascript.spec.js b/test/parser/javascript.spec.js index 445964371b..dc519f8468 100644 --- a/test/parser/javascript.spec.js +++ b/test/parser/javascript.spec.js @@ -1,4 +1,4 @@ -/* global describe, it */ +'use strict'; var assert = require('assert'); var Parser = require("../../lib/parser/javascript").Parser; diff --git a/test/pubsub.spec.js b/test/pubsub.spec.js index 3e6ad9ba68..3a3718b95b 100644 --- a/test/pubsub.spec.js +++ b/test/pubsub.spec.js @@ -1,3 +1,5 @@ +'use strict'; + var assert = require("assert"); var config = require("./lib/config"); var helper = require("./helper"); @@ -10,10 +12,9 @@ describe("publish/subscribe", function () { describe("using " + parser + " and " + ip, function () { var pub = null; var sub = null; - var channel = "test channel" - var channel2 = "test channel 2" - var message = "test message" - var hash = "test hash"; + var channel = "test channel"; + var channel2 = "test channel 2"; + var message = "test message"; beforeEach(function (done) { var pubConnected; @@ -166,7 +167,7 @@ describe("publish/subscribe", function () { }); describe('unsubscribe', function () { - it('fires an unsubscribe event', function () { + it('fires an unsubscribe event', function (done) { sub.on("subscribe", function (chnl, count) { sub.unsubscribe(channel) }); diff --git a/test/queue.spec.js b/test/queue.spec.js index f0b3c31648..51a6bd7bb2 100644 --- a/test/queue.spec.js +++ b/test/queue.spec.js @@ -1,3 +1,5 @@ +'use strict'; + var assert = require("assert"); var Queue = require('../lib/queue');