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

Replace jshint with eslint and add lots of rules

Fix eslint errors accordingly
This commit is contained in:
Ruben Bridgewater
2016-03-26 04:05:43 +01:00
parent 12579e5e8e
commit 94e9f1fcfc
98 changed files with 1621 additions and 1551 deletions

View File

@@ -1,22 +1,22 @@
'use strict';
var assert = require("assert");
var config = require("../lib/config");
var helper = require("../helper");
var assert = require('assert');
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
var intercept = require('intercept-stdout');
describe("The 'blpop' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var client;
var bclient;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.flushdb(done);
});
});
@@ -25,44 +25,44 @@ describe("The 'blpop' method", function () {
bclient = redis.createClient.apply(null, args);
redis.debug_mode = true;
var text = '';
var unhookIntercept = intercept(function(data) {
var unhookIntercept = intercept(function (data) {
text += data;
return '';
});
client.rpush("blocking list", "initial value", helper.isNumber(1));
client.rpush('blocking list', 'initial value', helper.isNumber(1));
unhookIntercept();
assert(/^Send 127\.0\.0\.1:6379 id [0-9]+: \*3\r\n\$5\r\nrpush\r\n\$13\r\nblocking list\r\n\$13\r\ninitial value\r\n\n$/.test(text));
redis.debug_mode = false;
bclient.blpop("blocking list", 0, function (err, value) {
assert.strictEqual(value[0], "blocking list");
assert.strictEqual(value[1], "initial value");
bclient.blpop('blocking list', 0, function (err, value) {
assert.strictEqual(value[0], 'blocking list');
assert.strictEqual(value[1], 'initial value');
return done(err);
});
});
it('pops value immediately if list contains values using array notation', function (done) {
bclient = redis.createClient.apply(null, args);
client.rpush(["blocking list", "initial value"], helper.isNumber(1));
bclient.blpop(["blocking list", 0], function (err, value) {
assert.strictEqual(value[0], "blocking list");
assert.strictEqual(value[1], "initial value");
client.rpush(['blocking list', 'initial value'], helper.isNumber(1));
bclient.blpop(['blocking list', 0], function (err, value) {
assert.strictEqual(value[0], 'blocking list');
assert.strictEqual(value[1], 'initial value');
return done(err);
});
});
it('waits for value if list is not yet populated', function (done) {
bclient = redis.createClient.apply(null, args);
bclient.blpop("blocking list 2", 5, function (err, value) {
assert.strictEqual(value[0], "blocking list 2");
assert.strictEqual(value[1], "initial value");
bclient.blpop('blocking list 2', 5, function (err, value) {
assert.strictEqual(value[0], 'blocking list 2');
assert.strictEqual(value[1], 'initial value');
return done(err);
});
client.rpush("blocking list 2", "initial value", helper.isNumber(1));
client.rpush('blocking list 2', 'initial value', helper.isNumber(1));
});
it('times out after specified time', function (done) {
bclient = redis.createClient.apply(null, args);
bclient.BLPOP("blocking list", 1, function (err, res) {
bclient.BLPOP('blocking list', 1, function (err, res) {
assert.strictEqual(res, null);
return done(err);
});

View File

@@ -1,21 +1,21 @@
'use strict';
var assert = require("assert");
var config = require("../lib/config");
var helper = require("../helper");
var assert = require('assert');
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
describe("The 'client' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
var pattern = /addr=/;
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.flushdb(done);
});
});
@@ -26,18 +26,18 @@ describe("The 'client' method", function () {
describe('list', function () {
it('lists connected clients', function (done) {
client.client("LIST", helper.match(pattern, done));
client.client('LIST', helper.match(pattern, done));
});
it("lists connected clients when invoked with multi's chaining syntax", function (done) {
client.multi().client("list").exec(function(err, results) {
client.multi().client('list').exec(function (err, results) {
assert(pattern.test(results[0]), "expected string '" + results + "' to match " + pattern.toString());
return done();
});
});
it("lists connected clients when invoked with array syntax on client", function (done) {
client.multi().client(["list"]).exec(function(err, results) {
it('lists connected clients when invoked with array syntax on client', function (done) {
client.multi().client(['list']).exec(function (err, results) {
assert(pattern.test(results[0]), "expected string '" + results + "' to match " + pattern.toString());
return done();
});
@@ -46,7 +46,7 @@ describe("The 'client' method", function () {
it("lists connected clients when invoked with multi's array syntax", function (done) {
client.multi([
['client', 'list']
]).exec(function(err, results) {
]).exec(function (err, results) {
assert(pattern.test(results[0]), "expected string '" + results + "' to match " + pattern.toString());
return done();
});
@@ -58,7 +58,7 @@ describe("The 'client' method", function () {
beforeEach(function (done) {
client2 = redis.createClient.apply(redis.createClient, args);
client2.once("ready", function () {
client2.once('ready', function () {
done();
});
});
@@ -72,14 +72,14 @@ describe("The 'client' method", function () {
// per chunk. So the execution order is only garanteed on each client
var end = helper.callFuncAfter(done, 2);
client.client("setname", "RUTH", helper.isString('OK'));
client2.client("setname", "RENEE", helper.isString('OK'));
client2.client("setname", "MARTIN", helper.isString('OK'));
client2.client("getname", function(err, res) {
client.client('setname', 'RUTH', helper.isString('OK'));
client2.client('setname', 'RENEE', helper.isString('OK'));
client2.client('setname', 'MARTIN', helper.isString('OK'));
client2.client('getname', function (err, res) {
assert.equal(res, 'MARTIN');
end();
});
client.client("getname", function(err, res) {
client.client('getname', function (err, res) {
assert.equal(res, 'RUTH');
end();
});

View File

@@ -1,16 +1,16 @@
'use strict';
var assert = require('assert');
var config = require("../lib/config");
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
var uuid = require('uuid');
describe("The 'dbsize' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var key, value;
beforeEach(function () {
@@ -18,18 +18,18 @@ describe("The 'dbsize' method", function () {
value = uuid.v4();
});
describe("when not connected", function () {
describe('when not connected', function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.quit();
});
client.on('end', done);
});
it("reports an error", function (done) {
it('reports an error', function (done) {
client.dbsize([], function (err, res) {
assert(err.message.match(/The connection has already been closed/));
done();
@@ -37,14 +37,14 @@ describe("The 'dbsize' method", function () {
});
});
describe("when connected", function () {
describe('when connected', function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.flushdb(function (err, res) {
helper.isString("OK")(err, res);
helper.isString('OK')(err, res);
done();
});
});
@@ -54,22 +54,22 @@ describe("The 'dbsize' method", function () {
client.end(true);
});
it("returns a zero db size", function (done) {
it('returns a zero db size', function (done) {
client.DBSIZE([], function (err, res) {
helper.isNotError()(err, res);
helper.isType.number()(err, res);
assert.strictEqual(res, 0, "Initial db size should be 0");
assert.strictEqual(res, 0, 'Initial db size should be 0');
done();
});
});
describe("when more data is added to Redis", function () {
describe('when more data is added to Redis', function () {
var oldSize;
beforeEach(function (done) {
client.dbsize(function (err, res) {
helper.isType.number()(err, res);
assert.strictEqual(res, 0, "Initial db size should be 0");
assert.strictEqual(res, 0, 'Initial db size should be 0');
oldSize = res;
@@ -80,11 +80,11 @@ describe("The 'dbsize' method", function () {
});
});
it("returns a larger db size", function (done) {
it('returns a larger db size', function (done) {
client.dbsize([], function (err, res) {
helper.isNotError()(err, res);
helper.isType.positiveNumber()(err, res);
assert.strictEqual(true, (oldSize < res), "Adding data should increase db size.");
assert.strictEqual(true, (oldSize < res), 'Adding data should increase db size.');
done();
});
});

View File

@@ -1,19 +1,19 @@
'use strict';
var config = require("../lib/config");
var helper = require("../helper");
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
describe("The 'del' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.flushdb(done);
});
});

View File

@@ -1,22 +1,22 @@
'use strict';
var assert = require("assert");
var config = require("../lib/config");
var crypto = require("crypto");
var helper = require("../helper");
var assert = require('assert');
var config = require('../lib/config');
var crypto = require('crypto');
var helper = require('../helper');
var redis = config.redis;
describe("The 'eval' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var client;
var source = "return redis.call('set', 'sha', 'test')";
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.flushdb(done);
});
});
@@ -26,7 +26,7 @@ describe("The 'eval' method", function () {
});
it('converts a float to an integer when evaluated', function (done) {
client.eval("return 100.5", 0, helper.isNumber(100, done));
client.eval('return 100.5', 0, helper.isNumber(100, done));
});
it('returns a string', function (done) {
@@ -34,11 +34,11 @@ describe("The 'eval' method", function () {
});
it('converts boolean true to integer 1', function (done) {
client.eval("return true", 0, helper.isNumber(1, done));
client.eval('return true', 0, helper.isNumber(1, done));
});
it('converts boolean false to null', function (done) {
client.eval("return false", 0, helper.isNull(done));
client.eval('return false', 0, helper.isNull(done));
});
it('converts lua status code to string representation', function (done) {
@@ -46,7 +46,7 @@ describe("The 'eval' method", function () {
});
it('converts lua error to an error response', function (done) {
client.eval("return {err='this is an error'}", 0, function(err) {
client.eval("return {err='this is an error'}", 0, function (err) {
assert(err.code === undefined);
helper.isError()(err);
done();
@@ -59,7 +59,7 @@ describe("The 'eval' method", function () {
assert.strictEqual(1, res[0]);
assert.strictEqual(2, res[1]);
assert.strictEqual(3, res[2]);
assert.strictEqual("ciao", res[3]);
assert.strictEqual('ciao', res[3]);
assert.strictEqual(2, res[4].length);
assert.strictEqual(1, res[4][0]);
assert.strictEqual(2, res[4][1]);
@@ -68,23 +68,23 @@ describe("The 'eval' method", function () {
});
it('populates keys and argv correctly', function (done) {
client.eval("return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}", 2, "a", "b", "c", "d", function (err, res) {
client.eval('return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}', 2, 'a', 'b', 'c', 'd', function (err, res) {
assert.strictEqual(4, res.length);
assert.strictEqual("a", res[0]);
assert.strictEqual("b", res[1]);
assert.strictEqual("c", res[2]);
assert.strictEqual("d", res[3]);
assert.strictEqual('a', res[0]);
assert.strictEqual('b', res[1]);
assert.strictEqual('c', res[2]);
assert.strictEqual('d', res[3]);
return done();
});
});
it('allows arguments to be provided in array rather than as multiple parameters', function (done) {
client.eval(["return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}", 2, "a", "b", "c", "d"], function (err, res) {
client.eval(['return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}', 2, 'a', 'b', 'c', 'd'], function (err, res) {
assert.strictEqual(4, res.length);
assert.strictEqual("a", res[0]);
assert.strictEqual("b", res[1]);
assert.strictEqual("c", res[2]);
assert.strictEqual("d", res[3]);
assert.strictEqual('a', res[0]);
assert.strictEqual('b', res[1]);
assert.strictEqual('c', res[2]);
assert.strictEqual('d', res[3]);
return done();
});
});
@@ -113,7 +113,7 @@ describe("The 'eval' method", function () {
it('emit an error if SHA does not exist without any callback', function (done) {
client.evalsha('ffffffffffffffffffffffffffffffffffffffff', 0);
client.on('error', function(err) {
client.on('error', function (err) {
assert.equal(err.code, 'NOSCRIPT');
assert(/NOSCRIPT No matching script. Please use EVAL./.test(err.message));
done();
@@ -130,11 +130,11 @@ describe("The 'eval' method", function () {
});
it('allows a key to be incremented, and performs appropriate conversion from LUA type', function (done) {
client.set("incr key", 0, function (err, reply) {
client.set('incr key', 0, function (err, reply) {
if (err) return done(err);
client.eval("local foo = redis.call('incr','incr key')\n" + "return {type(foo),foo}", 0, function (err, res) {
client.eval("local foo = redis.call('incr','incr key')\nreturn {type(foo),foo}", 0, function (err, res) {
assert.strictEqual(2, res.length);
assert.strictEqual("number", res[0]);
assert.strictEqual('number', res[0]);
assert.strictEqual(1, res[1]);
return done(err);
});
@@ -142,11 +142,11 @@ describe("The 'eval' method", function () {
});
it('allows a bulk operation to be performed, and performs appropriate conversion from LUA type', function (done) {
client.set("bulk reply key", "bulk reply value", function (err, res) {
client.set('bulk reply key', 'bulk reply value', function (err, res) {
client.eval("local foo = redis.call('get','bulk reply key'); return {type(foo),foo}", 0, function (err, res) {
assert.strictEqual(2, res.length);
assert.strictEqual("string", res[0]);
assert.strictEqual("bulk reply value", res[1]);
assert.strictEqual('string', res[0]);
assert.strictEqual('bulk reply value', res[1]);
return done(err);
});
});
@@ -154,18 +154,18 @@ describe("The 'eval' method", function () {
it('allows a multi mulk operation to be performed, with the appropriate type conversion', function (done) {
client.multi()
.del("mylist")
.rpush("mylist", "a")
.rpush("mylist", "b")
.rpush("mylist", "c")
.del('mylist')
.rpush('mylist', 'a')
.rpush('mylist', 'b')
.rpush('mylist', 'c')
.exec(function (err, replies) {
if (err) return done(err);
client.eval("local foo = redis.call('lrange','mylist',0,-1); return {type(foo),foo[1],foo[2],foo[3],# foo}", 0, function (err, res) {
assert.strictEqual(5, res.length);
assert.strictEqual("table", res[0]);
assert.strictEqual("a", res[1]);
assert.strictEqual("b", res[2]);
assert.strictEqual("c", res[3]);
assert.strictEqual('table', res[0]);
assert.strictEqual('a', res[1]);
assert.strictEqual('b', res[2]);
assert.strictEqual('c', res[3]);
assert.strictEqual(3, res[4]);
return done(err);
});
@@ -175,31 +175,31 @@ describe("The 'eval' method", function () {
it('returns an appropriate representation of Lua status reply', function (done) {
client.eval("local foo = redis.call('set','mykey','myval'); return {type(foo),foo['ok']}", 0, function (err, res) {
assert.strictEqual(2, res.length);
assert.strictEqual("table", res[0]);
assert.strictEqual("OK", res[1]);
assert.strictEqual('table', res[0]);
assert.strictEqual('OK', res[1]);
return done(err);
});
});
it('returns an appropriate representation of a Lua error reply', function (done) {
client.set("error reply key", "error reply value", function (err, res) {
client.set('error reply key', 'error reply value', function (err, res) {
if (err) return done(err);
client.eval("local foo = redis.pcall('incr','error reply key'); return {type(foo),foo['err']}", 0, function (err, res) {
assert.strictEqual(2, res.length);
assert.strictEqual("table", res[0]);
assert.strictEqual("ERR value is not an integer or out of range", res[1]);
assert.strictEqual('table', res[0]);
assert.strictEqual('ERR value is not an integer or out of range', res[1]);
return done(err);
});
});
});
it('returns an appropriate representation of a Lua nil reply', function (done) {
client.del("nil reply key", function (err, res) {
client.del('nil reply key', function (err, res) {
if (err) return done(err);
client.eval("local foo = redis.call('get','nil reply key'); return {type(foo),foo == false}", 0, function (err, res) {
if (err) throw err;
assert.strictEqual(2, res.length);
assert.strictEqual("boolean", res[0]);
assert.strictEqual('boolean', res[0]);
assert.strictEqual(1, res[1]);
return done(err);
});

View File

@@ -1,19 +1,19 @@
'use strict';
var config = require("../lib/config");
var helper = require("../helper");
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
describe("The 'exists' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.flushdb(done);
});
});

View File

@@ -1,36 +1,36 @@
'use strict';
var config = require("../lib/config");
var helper = require("../helper");
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
describe("The 'expire' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.flushdb(done);
});
});
it('expires key after timeout', function (done) {
client.set(['expiry key', 'bar'], helper.isString("OK"));
client.EXPIRE("expiry key", "1", helper.isNumber(1));
client.set(['expiry key', 'bar'], helper.isString('OK'));
client.EXPIRE('expiry key', '1', helper.isNumber(1));
setTimeout(function () {
client.exists(["expiry key"], helper.isNumber(0, done));
client.exists(['expiry key'], helper.isNumber(0, done));
}, 1100);
});
it('expires key after timeout with array syntax', function (done) {
client.set(['expiry key', 'bar'], helper.isString("OK"));
client.EXPIRE(["expiry key", "1"], helper.isNumber(1));
client.set(['expiry key', 'bar'], helper.isString('OK'));
client.EXPIRE(['expiry key', '1'], helper.isNumber(1));
setTimeout(function () {
client.exists(["expiry key"], helper.isNumber(0, done));
client.exists(['expiry key'], helper.isNumber(0, done));
}, 1100);
});

View File

@@ -1,16 +1,16 @@
'use strict';
var assert = require('assert');
var config = require("../lib/config");
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
var uuid = require('uuid');
describe("The 'flushdb' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var key, key2;
beforeEach(function () {
@@ -18,18 +18,18 @@ describe("The 'flushdb' method", function () {
key2 = uuid.v4();
});
describe("when not connected", function () {
describe('when not connected', function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.quit();
});
client.on('end', done);
});
it("reports an error", function (done) {
it('reports an error', function (done) {
client.flushdb(function (err, res) {
assert(err.message.match(/The connection has already been closed/));
done();
@@ -37,12 +37,12 @@ describe("The 'flushdb' method", function () {
});
});
describe("when connected", function () {
describe('when connected', function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
done();
});
});
@@ -51,7 +51,7 @@ describe("The 'flushdb' method", function () {
client.end(true);
});
describe("when there is data in Redis", function () {
describe('when there is data in Redis', function () {
beforeEach(function (done) {
client.mset(key, uuid.v4(), key2, uuid.v4(), helper.isNotError());
@@ -62,38 +62,38 @@ describe("The 'flushdb' method", function () {
});
});
it("deletes all the keys", function (done) {
client.flushdb(function(err, res) {
it('deletes all the keys', function (done) {
client.flushdb(function (err, res) {
assert.equal(res, 'OK');
client.mget(key, key2, function (err, res) {
assert.strictEqual(null, err, "Unexpected error returned");
assert.strictEqual(true, Array.isArray(res), "Results object should be an array.");
assert.strictEqual(2, res.length, "Results array should have length 2.");
assert.strictEqual(null, res[0], "Redis key should have been flushed.");
assert.strictEqual(null, res[1], "Redis key should have been flushed.");
assert.strictEqual(null, err, 'Unexpected error returned');
assert.strictEqual(true, Array.isArray(res), 'Results object should be an array.');
assert.strictEqual(2, res.length, 'Results array should have length 2.');
assert.strictEqual(null, res[0], 'Redis key should have been flushed.');
assert.strictEqual(null, res[1], 'Redis key should have been flushed.');
done(err);
});
});
});
it("results in a db size of zero", function (done) {
client.flushdb(function(err, res) {
it('results in a db size of zero', function (done) {
client.flushdb(function (err, res) {
client.dbsize([], function (err, res) {
helper.isNotError()(err, res);
helper.isType.number()(err, res);
assert.strictEqual(0, res, "Flushing db should result in db size 0");
assert.strictEqual(0, res, 'Flushing db should result in db size 0');
done();
});
});
});
it("results in a db size of zero without a callback", function (done) {
it('results in a db size of zero without a callback', function (done) {
client.flushdb();
setTimeout(function(err, res) {
setTimeout(function (err, res) {
client.dbsize([], function (err, res) {
helper.isNotError()(err, res);
helper.isType.number()(err, res);
assert.strictEqual(0, res, "Flushing db should result in db size 0");
assert.strictEqual(0, res, 'Flushing db should result in db size 0');
done();
});
}, 25);

View File

@@ -1,26 +1,26 @@
'use strict';
var config = require("../lib/config");
var helper = require("../helper");
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
describe("The 'geoadd' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.flushdb(done);
});
});
it('returns 1 if the key exists', function (done) {
helper.serverVersionAtLeast.call(this, client, [3, 2, 0]);
client.geoadd("mycity:21:0:location", "13.361389","38.115556","COR", function(err, res) {
client.geoadd('mycity:21:0:location', '13.361389', '38.115556', 'COR', function (err, res) {
console.log(err, res);
// geoadd is still in the unstable branch. As soon as it reaches the stable one, activate this test
done();

View File

@@ -1,16 +1,16 @@
'use strict';
var assert = require('assert');
var config = require("../lib/config");
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
var uuid = require('uuid');
describe("The 'get' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var key, value;
beforeEach(function () {
@@ -18,37 +18,37 @@ describe("The 'get' method", function () {
value = uuid.v4();
});
describe("when not connected", function () {
describe('when not connected', function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.quit();
});
client.on('end', done);
});
it("reports an error", function (done) {
it('reports an error', function (done) {
client.get(key, function (err, res) {
assert(err.message.match(/The connection has already been closed/));
done();
});
});
it("reports an error promisified", function () {
it('reports an error promisified', function () {
return client.getAsync(key).then(assert, function (err) {
assert(err.message.match(/The connection has already been closed/));
});
});
});
describe("when connected", function () {
describe('when connected', function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
done();
});
});
@@ -57,7 +57,7 @@ describe("The 'get' method", function () {
client.end(true);
});
describe("when the key exists in Redis", function () {
describe('when the key exists in Redis', function () {
beforeEach(function (done) {
client.set(key, value, function (err, res) {
helper.isNotError()(err, res);
@@ -65,7 +65,7 @@ describe("The 'get' method", function () {
});
});
it("gets the value correctly", function (done) {
it('gets the value correctly', function (done) {
client.GET(key, function (err, res) {
helper.isString(value)(err, res);
done(err);
@@ -74,15 +74,15 @@ describe("The 'get' method", function () {
it("should not throw on a get without callback (even if it's not useful)", function (done) {
client.GET(key);
client.on('error', function(err) {
client.on('error', function (err) {
throw err;
});
setTimeout(done, 50);
});
});
describe("when the key does not exist in Redis", function () {
it("gets a null value", function (done) {
describe('when the key does not exist in Redis', function () {
it('gets a null value', function (done) {
client.get(key, function (err, res) {
helper.isNull()(err, res);
done(err);

View File

@@ -1,16 +1,16 @@
'use strict';
var assert = require('assert');
var config = require("../lib/config");
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
var uuid = require('uuid');
describe("The 'getset' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var key, value, value2;
beforeEach(function () {
@@ -19,18 +19,18 @@ describe("The 'getset' method", function () {
value2 = uuid.v4();
});
describe("when not connected", function () {
describe('when not connected', function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.quit();
});
client.on('end', done);
});
it("reports an error", function (done) {
it('reports an error', function (done) {
client.get(key, function (err, res) {
assert(err.message.match(/The connection has already been closed/));
done();
@@ -38,12 +38,12 @@ describe("The 'getset' method", function () {
});
});
describe("when connected", function () {
describe('when connected', function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
done();
});
});
@@ -52,7 +52,7 @@ describe("The 'getset' method", function () {
client.end(true);
});
describe("when the key exists in Redis", function () {
describe('when the key exists in Redis', function () {
beforeEach(function (done) {
client.set(key, value, function (err, res) {
helper.isNotError()(err, res);
@@ -60,7 +60,7 @@ describe("The 'getset' method", function () {
});
});
it("gets the value correctly", function (done) {
it('gets the value correctly', function (done) {
client.GETSET(key, value2, function (err, res) {
helper.isString(value)(err, res);
client.get(key, function (err, res) {
@@ -70,7 +70,7 @@ describe("The 'getset' method", function () {
});
});
it("gets the value correctly with array syntax", function (done) {
it('gets the value correctly with array syntax', function (done) {
client.GETSET([key, value2], function (err, res) {
helper.isString(value)(err, res);
client.get(key, function (err, res) {
@@ -80,7 +80,7 @@ describe("The 'getset' method", function () {
});
});
it("gets the value correctly with array syntax style 2", function (done) {
it('gets the value correctly with array syntax style 2', function (done) {
client.GETSET(key, [value2], function (err, res) {
helper.isString(value)(err, res);
client.get(key, function (err, res) {
@@ -91,8 +91,8 @@ describe("The 'getset' method", function () {
});
});
describe("when the key does not exist in Redis", function () {
it("gets a null value", function (done) {
describe('when the key does not exist in Redis', function () {
it('gets a null value', function (done) {
client.getset(key, value, function (err, res) {
helper.isNull()(err, res);
done(err);

View File

@@ -1,48 +1,48 @@
'use strict';
var assert = require("assert");
var config = require("../lib/config");
var helper = require("../helper");
var assert = require('assert');
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
describe("The 'hgetall' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var client;
describe('regular client', function () {
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.flushdb(done);
});
});
it('handles simple keys and values', function (done) {
client.hmset(["hosts", "mjr", "1", "another", "23", "home", "1234"], helper.isString("OK"));
client.HGETALL(["hosts"], function (err, obj) {
client.hmset(['hosts', 'mjr', '1', 'another', '23', 'home', '1234'], helper.isString('OK'));
client.HGETALL(['hosts'], function (err, obj) {
assert.strictEqual(3, Object.keys(obj).length);
assert.strictEqual("1", obj.mjr.toString());
assert.strictEqual("23", obj.another.toString());
assert.strictEqual("1234", obj.home.toString());
assert.strictEqual('1', obj.mjr.toString());
assert.strictEqual('23', obj.another.toString());
assert.strictEqual('1234', obj.home.toString());
return done(err);
});
});
it('handles fetching keys set using an object', function (done) {
client.HMSET("msg_test", { message: "hello" }, helper.isString("OK"));
client.hgetall("msg_test", function (err, obj) {
client.HMSET('msg_test', { message: 'hello' }, helper.isString('OK'));
client.hgetall('msg_test', function (err, obj) {
assert.strictEqual(1, Object.keys(obj).length);
assert.strictEqual(obj.message, "hello");
assert.strictEqual(obj.message, 'hello');
return done(err);
});
});
it('handles fetching a messing key', function (done) {
client.hgetall("missing", function (err, obj) {
client.hgetall('missing', function (err, obj) {
assert.strictEqual(null, obj);
return done(err);
});
@@ -57,18 +57,18 @@ describe("The 'hgetall' method", function () {
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.flushdb(done);
});
});
it('returns binary results', function (done) {
client.hmset(["bhosts", "mjr", "1", "another", "23", "home", "1234", new Buffer([0xAA, 0xBB, 0x00, 0xF0]), new Buffer([0xCC, 0xDD, 0x00, 0xF0])], helper.isString("OK"));
client.HGETALL("bhosts", function (err, obj) {
client.hmset(['bhosts', 'mjr', '1', 'another', '23', 'home', '1234', new Buffer([0xAA, 0xBB, 0x00, 0xF0]), new Buffer([0xCC, 0xDD, 0x00, 0xF0])], helper.isString('OK'));
client.HGETALL('bhosts', function (err, obj) {
assert.strictEqual(4, Object.keys(obj).length);
assert.strictEqual("1", obj.mjr.toString());
assert.strictEqual("23", obj.another.toString());
assert.strictEqual("1234", obj.home.toString());
assert.strictEqual('1', obj.mjr.toString());
assert.strictEqual('23', obj.another.toString());
assert.strictEqual('1234', obj.home.toString());
assert.strictEqual((new Buffer([0xAA, 0xBB, 0x00, 0xF0])).toString('binary'), Object.keys(obj)[3]);
assert.strictEqual((new Buffer([0xCC, 0xDD, 0x00, 0xF0])).toString('binary'), obj[(new Buffer([0xAA, 0xBB, 0x00, 0xF0])).toString('binary')].toString('binary'));
return done(err);

View File

@@ -1,33 +1,33 @@
'use strict';
var config = require("../lib/config");
var helper = require("../helper");
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
describe("The 'hincrby' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var client;
var hash = "test hash";
var hash = 'test hash';
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.flushdb(done);
});
});
it('increments a key that has already been set', function (done) {
var field = "field 1";
var field = 'field 1';
client.HSET(hash, field, 33);
client.hincrby(hash, field, 10, helper.isNumber(43, done));
});
it('increments a key that has not been set', function (done) {
var field = "field 2";
var field = 'field 2';
client.HINCRBY(hash, field, 10, helper.isNumber(10, done));
});

View File

@@ -1,27 +1,27 @@
'use strict';
var config = require("../lib/config");
var helper = require("../helper");
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
describe("The 'hlen' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.flushdb(done);
});
});
it('reports the count of keys', function (done) {
var hash = "test hash";
var field1 = new Buffer("0123456789");
var value1 = new Buffer("abcdefghij");
var hash = 'test hash';
var field1 = new Buffer('0123456789');
var value1 = new Buffer('abcdefghij');
var field2 = new Buffer(0);
var value2 = new Buffer(0);

View File

@@ -1,62 +1,62 @@
'use strict';
var assert = require("assert");
var config = require("../lib/config");
var helper = require("../helper");
var assert = require('assert');
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
describe("The 'hmget' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var client;
var hash = 'test hash';
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("error", done);
client.once("ready", function () {
client.once('error', done);
client.once('ready', function () {
client.flushdb();
client.HMSET(hash, {"0123456789": "abcdefghij", "some manner of key": "a type of value"}, helper.isString('OK', done));
client.HMSET(hash, {'0123456789': 'abcdefghij', 'some manner of key': 'a type of value'}, helper.isString('OK', done));
});
});
it('allows keys to be specified using multiple arguments', function (done) {
client.hmget(hash, "0123456789", "some manner of key", function (err, reply) {
assert.strictEqual("abcdefghij", reply[0].toString());
assert.strictEqual("a type of value", reply[1].toString());
client.hmget(hash, '0123456789', 'some manner of key', function (err, reply) {
assert.strictEqual('abcdefghij', reply[0].toString());
assert.strictEqual('a type of value', reply[1].toString());
return done(err);
});
});
it('allows keys to be specified by passing an array without manipulating the array', function (done) {
var data = ["0123456789", "some manner of key"];
var data = ['0123456789', 'some manner of key'];
client.HMGET(hash, data, function (err, reply) {
assert.strictEqual(data.length, 2);
assert.strictEqual("abcdefghij", reply[0].toString());
assert.strictEqual("a type of value", reply[1].toString());
assert.strictEqual('abcdefghij', reply[0].toString());
assert.strictEqual('a type of value', reply[1].toString());
return done(err);
});
});
it('allows keys to be specified by passing an array as first argument', function (done) {
client.HMGET([hash, "0123456789", "some manner of key"], function (err, reply) {
assert.strictEqual("abcdefghij", reply[0].toString());
assert.strictEqual("a type of value", reply[1].toString());
client.HMGET([hash, '0123456789', 'some manner of key'], function (err, reply) {
assert.strictEqual('abcdefghij', reply[0].toString());
assert.strictEqual('a type of value', reply[1].toString());
return done(err);
});
});
it('allows a single key to be specified in an array', function (done) {
client.HMGET(hash, ["0123456789"], function (err, reply) {
assert.strictEqual("abcdefghij", reply[0].toString());
client.HMGET(hash, ['0123456789'], function (err, reply) {
assert.strictEqual('abcdefghij', reply[0].toString());
return done(err);
});
});
it('allows keys to be specified that have not yet been set', function (done) {
client.HMGET(hash, "missing thing", "another missing thing", function (err, reply) {
client.HMGET(hash, 'missing thing', 'another missing thing', function (err, reply) {
assert.strictEqual(null, reply[0]);
assert.strictEqual(null, reply[1]);
return done(err);

View File

@@ -1,27 +1,27 @@
'use strict';
var assert = require("assert");
var config = require("../lib/config");
var helper = require("../helper");
var assert = require('assert');
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
describe("The 'hmset' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var client;
var hash = 'test hash';
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.flushdb(done);
});
});
it('handles redis-style syntax', function (done) {
client.HMSET(hash, "0123456789", "abcdefghij", "some manner of key", "a type of value", "otherTypes", 555, helper.isString('OK'));
client.HMSET(hash, '0123456789', 'abcdefghij', 'some manner of key', 'a type of value', 'otherTypes', 555, helper.isString('OK'));
client.HGETALL(hash, function (err, obj) {
assert.equal(obj['0123456789'], 'abcdefghij');
assert.equal(obj['some manner of key'], 'a type of value');
@@ -30,7 +30,7 @@ describe("The 'hmset' method", function () {
});
it('handles object-style syntax', function (done) {
client.hmset(hash, {"0123456789": "abcdefghij", "some manner of key": "a type of value", "otherTypes": 555}, helper.isString('OK'));
client.hmset(hash, {'0123456789': 'abcdefghij', 'some manner of key': 'a type of value', 'otherTypes': 555}, helper.isString('OK'));
client.HGETALL(hash, function (err, obj) {
assert.equal(obj['0123456789'], 'abcdefghij');
assert.equal(obj['some manner of key'], 'a type of value');
@@ -39,7 +39,7 @@ describe("The 'hmset' method", function () {
});
it('handles object-style syntax and the key being a number', function (done) {
client.HMSET(231232, {"0123456789": "abcdefghij", "some manner of key": "a type of value", "otherTypes": 555}, helper.isString('OK'));
client.HMSET(231232, {'0123456789': 'abcdefghij', 'some manner of key': 'a type of value', 'otherTypes': 555}, helper.isString('OK'));
client.HGETALL(231232, function (err, obj) {
assert.equal(obj['0123456789'], 'abcdefghij');
assert.equal(obj['some manner of key'], 'a type of value');
@@ -101,7 +101,7 @@ describe("The 'hmset' method", function () {
});
it('handles object-style syntax without callback', function (done) {
client.HMSET(hash, {"0123456789": "abcdefghij", "some manner of key": "a type of value"});
client.HMSET(hash, {'0123456789': 'abcdefghij', 'some manner of key': 'a type of value'});
client.HGETALL(hash, function (err, obj) {
assert.equal(obj['0123456789'], 'abcdefghij');
assert.equal(obj['some manner of key'], 'a type of value');

View File

@@ -1,39 +1,39 @@
'use strict';
var assert = require("assert");
var config = require("../lib/config");
var helper = require("../helper");
var assert = require('assert');
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
describe("The 'hset' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var client;
var hash = 'test hash';
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.flushdb(done);
});
});
it('allows a value to be set in a hash', function (done) {
var field = new Buffer("0123456789");
var value = new Buffer("abcdefghij");
var field = new Buffer('0123456789');
var value = new Buffer('abcdefghij');
client.hset(hash, field, value, helper.isNumber(1));
client.HGET(hash, field, helper.isString(value.toString(), done));
});
it('handles an empty value', function (done) {
var field = new Buffer("0123456789");
var field = new Buffer('0123456789');
var value = new Buffer(0);
client.HSET(hash, field, value, helper.isNumber(1));
client.HGET([hash, field], helper.isString("", done));
client.HGET([hash, field], helper.isString('', done));
});
it('handles empty key and value', function (done) {
@@ -46,11 +46,11 @@ describe("The 'hset' method", function () {
});
it('warns if someone passed a array either as field or as value', function (done) {
var hash = "test hash";
var field = "array";
var hash = 'test hash';
var field = 'array';
// This would be converted to "array contents" but if you use more than one entry,
// it'll result in e.g. "array contents,second content" and this is not supported and considered harmful
var value = ["array contents"];
var value = ['array contents'];
client.on('warning', function (msg) {
assert.strictEqual(
msg,
@@ -64,23 +64,23 @@ describe("The 'hset' method", function () {
});
it('does not error when a buffer and date are set as values on the same hash', function (done) {
var hash = "test hash";
var field1 = "buffer";
var value1 = new Buffer("abcdefghij");
var field2 = "date";
var hash = 'test hash';
var field1 = 'buffer';
var value1 = new Buffer('abcdefghij');
var field2 = 'date';
var value2 = new Date();
client.HMSET(hash, field1, value1, field2, value2, helper.isString("OK", done));
client.HMSET(hash, field1, value1, field2, value2, helper.isString('OK', done));
});
it('does not error when a buffer and date are set as fields on the same hash', function (done) {
var hash = "test hash";
var value1 = "buffer";
var field1 = new Buffer("abcdefghij");
var value2 = "date";
var hash = 'test hash';
var value1 = 'buffer';
var field1 = new Buffer('abcdefghij');
var value2 = 'date';
var field2 = new Date();
client.HMSET(hash, field1, value1, field2, value2, helper.isString("OK", done));
client.HMSET(hash, field1, value1, field2, value2, helper.isString('OK', done));
});
afterEach(function () {

View File

@@ -1,24 +1,24 @@
'use strict';
var assert = require('assert');
var config = require("../lib/config");
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
describe("The 'incr' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
var key = "sequence";
describe('using ' + parser + ' and ' + ip, function () {
var key = 'sequence';
describe("when not connected", function () {
describe('when not connected', function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.set(key, "9007199254740992", function (err, res) {
client.once('ready', function () {
client.set(key, '9007199254740992', function (err, res) {
helper.isNotError()(err, res);
client.quit();
});
@@ -30,7 +30,7 @@ describe("The 'incr' method", function () {
client.end(true);
});
it("reports an error", function (done) {
it('reports an error', function (done) {
client.incr(function (err, res) {
assert(err.message.match(/The connection has already been closed/));
done();
@@ -38,7 +38,7 @@ describe("The 'incr' method", function () {
});
});
describe("when connected and a value in Redis", function () {
describe('when connected and a value in Redis', function () {
var client;
before(function (done) {
@@ -51,9 +51,9 @@ describe("The 'incr' method", function () {
9007199254740997 -> 9007199254740996
*/
client = redis.createClient.apply(null, args);
client.once("error", done);
client.once("ready", function () {
client.set(key, "9007199254740992", function (err, res) {
client.once('error', done);
client.once('ready', function () {
client.set(key, '9007199254740992', function (err, res) {
helper.isNotError()(err, res);
done();
});
@@ -64,41 +64,41 @@ describe("The 'incr' method", function () {
client.end(true);
});
it("changes the last digit from 2 to 3", function (done) {
it('changes the last digit from 2 to 3', function (done) {
client.INCR(key, function (err, res) {
helper.isString("9007199254740993")(err, res);
helper.isString('9007199254740993')(err, res);
done(err);
});
});
describe("and we call it again", function () {
it("changes the last digit from 3 to 4", function (done) {
describe('and we call it again', function () {
it('changes the last digit from 3 to 4', function (done) {
client.incr(key, function (err, res) {
helper.isString("9007199254740994")(err, res);
helper.isString('9007199254740994')(err, res);
done(err);
});
});
describe("and again", function () {
it("changes the last digit from 4 to 5", function (done) {
describe('and again', function () {
it('changes the last digit from 4 to 5', function (done) {
client.incr(key, function (err, res) {
helper.isString("9007199254740995")(err, res);
helper.isString('9007199254740995')(err, res);
done(err);
});
});
describe("and again", function () {
it("changes the last digit from 5 to 6", function (done) {
describe('and again', function () {
it('changes the last digit from 5 to 6', function (done) {
client.incr(key, function (err, res) {
helper.isString("9007199254740996")(err, res);
helper.isString('9007199254740996')(err, res);
done(err);
});
});
describe("and again", function () {
it("changes the last digit from 6 to 7", function (done) {
describe('and again', function () {
it('changes the last digit from 6 to 7', function (done) {
client.incr(key, function (err, res) {
helper.isString("9007199254740997")(err, res);
helper.isString('9007199254740997')(err, res);
done(err);
});
});

View File

@@ -1,20 +1,20 @@
'use strict';
var assert = require('assert');
var config = require("../lib/config");
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
describe("The 'info' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.flushall(done);
});
});
@@ -23,7 +23,7 @@ describe("The 'info' method", function () {
client.end(true);
});
it("update server_info after a info command", function (done) {
it('update server_info after a info command', function (done) {
client.set('foo', 'bar');
client.info();
client.select(2, function () {
@@ -37,7 +37,7 @@ describe("The 'info' method", function () {
}, 150);
});
it("works with optional section provided with and without callback", function (done) {
it('works with optional section provided with and without callback', function (done) {
client.set('foo', 'bar');
client.info('keyspace');
client.select(2, function () {
@@ -65,7 +65,7 @@ describe("The 'info' method", function () {
client.info(function () {});
});
it("emit error after a failure", function (done) {
it('emit error after a failure', function (done) {
client.info();
client.once('error', function (err) {
assert.strictEqual(err.code, 'UNCERTAIN_STATE');

View File

@@ -1,31 +1,31 @@
'use strict';
var assert = require("assert");
var config = require("../lib/config");
var crypto = require("crypto");
var helper = require("../helper");
var assert = require('assert');
var config = require('../lib/config');
var crypto = require('crypto');
var helper = require('../helper');
var redis = config.redis;
describe("The 'keys' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.flushall(done);
});
});
it('returns matching keys', function (done) {
client.mset(["test keys 1", "test val 1", "test keys 2", "test val 2"], helper.isString("OK"));
client.KEYS("test keys*", function (err, results) {
client.mset(['test keys 1', 'test val 1', 'test keys 2', 'test val 2'], helper.isString('OK'));
client.KEYS('test keys*', function (err, results) {
assert.strictEqual(2, results.length);
assert.ok(~results.indexOf("test keys 1"));
assert.ok(~results.indexOf("test keys 2"));
assert.ok(~results.indexOf('test keys 1'));
assert.ok(~results.indexOf('test keys 2'));
return done(err);
});
});
@@ -35,18 +35,18 @@ describe("The 'keys' method", function () {
for (var i = 0; i < 200; i++) {
var key_value = [
"multibulk:" + crypto.randomBytes(256).toString("hex"), // use long strings as keys to ensure generation of large packet
"test val " + i
'multibulk:' + crypto.randomBytes(256).toString('hex'), // use long strings as keys to ensure generation of large packet
'test val ' + i
];
keys_values.push(key_value);
}
client.mset(keys_values.reduce(function(a, b) {
client.mset(keys_values.reduce(function (a, b) {
return a.concat(b);
}), helper.isString("OK"));
}), helper.isString('OK'));
client.keys("multibulk:*", function(err, results) {
assert.deepEqual(keys_values.map(function(val) {
client.keys('multibulk:*', function (err, results) {
assert.deepEqual(keys_values.map(function (val) {
return val[0];
}).sort(), results.sort());
return done(err);

View File

@@ -1,64 +1,64 @@
'use strict';
var assert = require("assert");
var config = require("../lib/config");
var helper = require("../helper");
var assert = require('assert');
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
describe("The 'mget' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("error", done);
client.once("ready", function () {
client.once('error', done);
client.once('ready', function () {
client.flushdb();
client.mset(["mget keys 1", "mget val 1", "mget keys 2", "mget val 2", "mget keys 3", "mget val 3"], done);
client.mset(['mget keys 1', 'mget val 1', 'mget keys 2', 'mget val 2', 'mget keys 3', 'mget val 3'], done);
});
});
it('handles fetching multiple keys in argument form', function (done) {
client.mset(["mget keys 1", "mget val 1", "mget keys 2", "mget val 2", "mget keys 3", "mget val 3"], helper.isString("OK"));
client.MGET("mget keys 1", "mget keys 2", "mget keys 3", function (err, results) {
client.mset(['mget keys 1', 'mget val 1', 'mget keys 2', 'mget val 2', 'mget keys 3', 'mget val 3'], helper.isString('OK'));
client.MGET('mget keys 1', 'mget keys 2', 'mget keys 3', function (err, results) {
assert.strictEqual(3, results.length);
assert.strictEqual("mget val 1", results[0].toString());
assert.strictEqual("mget val 2", results[1].toString());
assert.strictEqual("mget val 3", results[2].toString());
assert.strictEqual('mget val 1', results[0].toString());
assert.strictEqual('mget val 2', results[1].toString());
assert.strictEqual('mget val 3', results[2].toString());
return done(err);
});
});
it('handles fetching multiple keys via an array', function (done) {
client.mget(["mget keys 1", "mget keys 2", "mget keys 3"], function (err, results) {
assert.strictEqual("mget val 1", results[0].toString());
assert.strictEqual("mget val 2", results[1].toString());
assert.strictEqual("mget val 3", results[2].toString());
client.mget(['mget keys 1', 'mget keys 2', 'mget keys 3'], function (err, results) {
assert.strictEqual('mget val 1', results[0].toString());
assert.strictEqual('mget val 2', results[1].toString());
assert.strictEqual('mget val 3', results[2].toString());
return done(err);
});
});
it('handles fetching multiple keys, when some keys do not exist', function (done) {
client.MGET("mget keys 1", ["some random shit", "mget keys 2", "mget keys 3"], function (err, results) {
client.MGET('mget keys 1', ['some random shit', 'mget keys 2', 'mget keys 3'], function (err, results) {
assert.strictEqual(4, results.length);
assert.strictEqual("mget val 1", results[0].toString());
assert.strictEqual('mget val 1', results[0].toString());
assert.strictEqual(null, results[1]);
assert.strictEqual("mget val 2", results[2].toString());
assert.strictEqual("mget val 3", results[3].toString());
assert.strictEqual('mget val 2', results[2].toString());
assert.strictEqual('mget val 3', results[3].toString());
return done(err);
});
});
it('handles fetching multiple keys, when some keys do not exist promisified', function () {
return client.MGETAsync("mget keys 1", ["some random shit", "mget keys 2", "mget keys 3"]).then(function (results) {
return client.MGETAsync('mget keys 1', ['some random shit', 'mget keys 2', 'mget keys 3']).then(function (results) {
assert.strictEqual(4, results.length);
assert.strictEqual("mget val 1", results[0].toString());
assert.strictEqual('mget val 1', results[0].toString());
assert.strictEqual(null, results[1]);
assert.strictEqual("mget val 2", results[2].toString());
assert.strictEqual("mget val 3", results[3].toString());
assert.strictEqual('mget val 2', results[2].toString());
assert.strictEqual('mget val 3', results[3].toString());
});
});

View File

@@ -1,16 +1,16 @@
'use strict';
var assert = require('assert');
var config = require("../lib/config");
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
var uuid = require('uuid');
describe("The 'mset' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var key, value, key2, value2;
beforeEach(function () {
@@ -20,18 +20,18 @@ describe("The 'mset' method", function () {
value2 = uuid.v4();
});
describe("when not connected", function () {
describe('when not connected', function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.quit();
});
client.on('end', done);
});
it("reports an error", function (done) {
it('reports an error', function (done) {
client.mset(key, value, key2, value2, function (err, res) {
assert(err.message.match(/The connection has already been closed/));
done();
@@ -39,12 +39,12 @@ describe("The 'mset' method", function () {
});
});
describe("when connected", function () {
describe('when connected', function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
done();
});
});
@@ -53,10 +53,10 @@ describe("The 'mset' method", function () {
client.end(true);
});
describe("and a callback is specified", function () {
describe("with valid parameters", function () {
it("sets the value correctly", function (done) {
client.mset(key, value, key2, value2, function(err) {
describe('and a callback is specified', function () {
describe('with valid parameters', function () {
it('sets the value correctly', function (done) {
client.mset(key, value, key2, value2, function (err) {
if (err) {
return done(err);
}
@@ -67,7 +67,7 @@ describe("The 'mset' method", function () {
});
describe("with undefined 'key' parameter and missing 'value' parameter", function () {
it("reports an error", function (done) {
it('reports an error', function (done) {
client.mset(undefined, function (err, res) {
helper.isError()(err, null);
done();
@@ -77,15 +77,15 @@ describe("The 'mset' method", function () {
});
describe("and no callback is specified", function () {
describe("with valid parameters", function () {
it("sets the value correctly", function (done) {
describe('and no callback is specified', function () {
describe('with valid parameters', function () {
it('sets the value correctly', function (done) {
client.mset(key, value2, key2, value);
client.get(key, helper.isString(value2));
client.get(key2, helper.isString(value, done));
});
it("sets the value correctly with array syntax", function (done) {
it('sets the value correctly with array syntax', function (done) {
client.mset([key, value2, key2, value]);
client.get(key, helper.isString(value2));
client.get(key2, helper.isString(value, done));
@@ -94,7 +94,7 @@ describe("The 'mset' method", function () {
describe("with undefined 'key' and missing 'value' parameter", function () {
// this behavior is different from the 'set' behavior.
it("emits an error", function (done) {
it('emits an error', function (done) {
client.on('error', function (err) {
assert.equal(err.message, "ERR wrong number of arguments for 'mset' command");
done();

View File

@@ -1,33 +1,33 @@
'use strict';
var config = require("../lib/config");
var helper = require("../helper");
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
describe("The 'msetnx' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.flushdb(done);
});
});
it('if any keys exist entire operation fails', function (done) {
client.mset(["mset1", "val1", "mset2", "val2", "mset3", "val3"], helper.isString("OK"));
client.MSETNX(["mset3", "val3", "mset4", "val4"], helper.isNumber(0));
client.exists(["mset4"], helper.isNumber(0, done));
client.mset(['mset1', 'val1', 'mset2', 'val2', 'mset3', 'val3'], helper.isString('OK'));
client.MSETNX(['mset3', 'val3', 'mset4', 'val4'], helper.isNumber(0));
client.exists(['mset4'], helper.isNumber(0, done));
});
it('sets multiple keys if all keys are not set', function (done) {
client.msetnx(["mset3", "val3", "mset4", "val4"], helper.isNumber(1));
client.exists(["mset3"], helper.isNumber(1));
client.exists(["mset3"], helper.isNumber(1, done));
client.msetnx(['mset3', 'val3', 'mset4', 'val4'], helper.isNumber(1));
client.exists(['mset3'], helper.isNumber(1));
client.exists(['mset3'], helper.isNumber(1, done));
});
afterEach(function () {

View File

@@ -1,26 +1,26 @@
'use strict';
var assert = require("assert");
var config = require("../lib/config");
var helper = require("../helper");
var assert = require('assert');
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
describe("The 'randomkey' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.flushdb(done);
});
});
it('returns a random key', function (done) {
client.mset(["test keys 1", "test val 1", "test keys 2", "test val 2"], helper.isString('OK'));
client.mset(['test keys 1', 'test val 1', 'test keys 2', 'test val 2'], helper.isString('OK'));
client.RANDOMKEY([], function (err, results) {
assert.strictEqual(true, /test keys.+/.test(results));
return done(err);

View File

@@ -1,33 +1,33 @@
'use strict';
var config = require("../lib/config");
var helper = require("../helper");
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
describe("The 'rename' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.flushdb(done);
});
});
it('populates the new key', function (done) {
client.set(['foo', 'bar'], helper.isString("OK"));
client.rename(["foo", "new foo"], helper.isString("OK"));
client.exists(["new foo"], helper.isNumber(1, done));
client.set(['foo', 'bar'], helper.isString('OK'));
client.rename(['foo', 'new foo'], helper.isString('OK'));
client.exists(['new foo'], helper.isNumber(1, done));
});
it('removes the old key', function (done) {
client.set(['foo', 'bar'], helper.isString("OK"));
client.RENAME(["foo", "new foo"], helper.isString("OK"));
client.exists(["foo"], helper.isNumber(0, done));
client.set(['foo', 'bar'], helper.isString('OK'));
client.RENAME(['foo', 'new foo'], helper.isString('OK'));
client.exists(['foo'], helper.isNumber(0, done));
});
afterEach(function () {

View File

@@ -1,19 +1,19 @@
'use strict';
var config = require("../lib/config");
var helper = require("../helper");
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
describe("The 'renamenx' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.flushdb(done);
});
});

View File

@@ -1,27 +1,27 @@
'use strict';
var config = require("../lib/config");
var helper = require("../helper");
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
var assert = require('assert');
describe("The 'rpush' command", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.flushdb(done);
});
});
it('inserts multiple values at a time into a list', function (done) {
client.rpush('test', ['list key', 'should be a list']);
client.lrange('test', 0, -1, function(err, res) {
client.lrange('test', 0, -1, function (err, res) {
assert.equal(res[0], 'list key');
assert.equal(res[1], 'should be a list');
done(err);

View File

@@ -1,20 +1,20 @@
'use strict';
var assert = require("assert");
var config = require("../lib/config");
var helper = require("../helper");
var assert = require('assert');
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
describe("The 'sadd' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.flushdb(done);
});
});
@@ -33,23 +33,23 @@ describe("The 'sadd' method", function () {
});
it('allows multiple values to be added to the set', function (done) {
client.sadd("set0", ["member0", "member1", "member2"], helper.isNumber(3));
client.smembers("set0", function (err, res) {
client.sadd('set0', ['member0', 'member1', 'member2'], helper.isNumber(3));
client.smembers('set0', function (err, res) {
assert.strictEqual(res.length, 3);
assert.ok(~res.indexOf("member0"));
assert.ok(~res.indexOf("member1"));
assert.ok(~res.indexOf("member2"));
assert.ok(~res.indexOf('member0'));
assert.ok(~res.indexOf('member1'));
assert.ok(~res.indexOf('member2'));
return done(err);
});
});
it('allows multiple values to be added to the set with a different syntax', function (done) {
client.sadd(["set0", "member0", "member1", "member2"], helper.isNumber(3));
client.smembers("set0", function (err, res) {
client.sadd(['set0', 'member0', 'member1', 'member2'], helper.isNumber(3));
client.smembers('set0', function (err, res) {
assert.strictEqual(res.length, 3);
assert.ok(~res.indexOf("member0"));
assert.ok(~res.indexOf("member1"));
assert.ok(~res.indexOf("member2"));
assert.ok(~res.indexOf('member0'));
assert.ok(~res.indexOf('member1'));
assert.ok(~res.indexOf('member2'));
return done(err);
});
});

View File

@@ -1,19 +1,19 @@
'use strict';
var config = require("../lib/config");
var helper = require("../helper");
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
describe("The 'scard' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.flushdb(done);
});
});

View File

@@ -1,23 +1,23 @@
'use strict';
var assert = require("assert");
var config = require("../lib/config");
var crypto = require("crypto");
var helper = require("../helper");
var assert = require('assert');
var config = require('../lib/config');
var crypto = require('crypto');
var helper = require('../helper');
var redis = config.redis;
describe("The 'script' method", function () {
helper.allTests(function(parser, ip, args) {
var command = "return 99";
helper.allTests(function (parser, ip, args) {
var command = 'return 99';
var commandSha = crypto.createHash('sha1').update(command).digest('hex');
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.flushdb(done);
});
});
@@ -27,7 +27,7 @@ describe("The 'script' method", function () {
});
it("loads script with client.script('load')", function (done) {
client.script("load", command, function(err, result) {
client.script('load', command, function (err, result) {
assert.strictEqual(result, commandSha);
return done();
});
@@ -38,14 +38,14 @@ describe("The 'script' method", function () {
});
it('allows a script to be loaded as part of a chained transaction', function (done) {
client.multi().script("load", command).exec(function(err, result) {
client.multi().script('load', command).exec(function (err, result) {
assert.strictEqual(result[0], commandSha);
return done();
});
});
it("allows a script to be loaded using a transaction's array syntax", function (done) {
client.multi([['script', 'load', command]]).exec(function(err, result) {
client.multi([['script', 'load', command]]).exec(function (err, result) {
assert.strictEqual(result[0], commandSha);
return done();
});

View File

@@ -1,20 +1,20 @@
'use strict';
var assert = require("assert");
var config = require("../lib/config");
var helper = require("../helper");
var assert = require('assert');
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
describe("The 'sdiff' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.flushdb(done);
});
});

View File

@@ -1,20 +1,20 @@
'use strict';
var assert = require("assert");
var config = require("../lib/config");
var helper = require("../helper");
var assert = require('assert');
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
describe("The 'sdiffstore' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.flushdb(done);
});
});

View File

@@ -1,27 +1,27 @@
'use strict';
var assert = require('assert');
var config = require("../lib/config");
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
describe("The 'select' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
describe("when not connected", function () {
describe('using ' + parser + ' and ' + ip, function () {
describe('when not connected', function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.quit();
});
client.on('end', done);
});
it("returns an error if redis is not connected", function (done) {
it('returns an error if redis is not connected', function (done) {
var buffering = client.select(1, function (err, res) {
assert(err.message.match(/The connection has already been closed/));
done();
@@ -30,12 +30,12 @@ describe("The 'select' method", function () {
});
});
describe("when connected", function () {
describe('when connected', function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.flushdb(done);
});
});
@@ -44,32 +44,32 @@ describe("The 'select' method", function () {
client.end(true);
});
it("changes the database and calls the callback", function (done) {
it('changes the database and calls the callback', function (done) {
// default value of null means database 0 will be used.
assert.strictEqual(client.selected_db, undefined, "default db should be undefined");
assert.strictEqual(client.selected_db, undefined, 'default db should be undefined');
var buffering = client.SELECT(1, function (err, res) {
helper.isNotError()(err, res);
assert.strictEqual(client.selected_db, 1, "db should be 1 after select");
assert.strictEqual(client.selected_db, 1, 'db should be 1 after select');
done();
});
assert(typeof buffering === 'boolean');
});
describe("and a callback is specified", function () {
describe("with a valid db index", function () {
it("selects the appropriate database", function (done) {
assert.strictEqual(client.selected_db, undefined, "default db should be undefined");
describe('and a callback is specified', function () {
describe('with a valid db index', function () {
it('selects the appropriate database', function (done) {
assert.strictEqual(client.selected_db, undefined, 'default db should be undefined');
client.select(1, function (err) {
assert.equal(err, null);
assert.equal(client.selected_db, 1, "we should have selected the new valid DB");
assert.equal(client.selected_db, 1, 'we should have selected the new valid DB');
return done();
});
});
});
describe("with an invalid db index", function () {
it("returns an error", function (done) {
assert.strictEqual(client.selected_db, undefined, "default db should be undefined");
describe('with an invalid db index', function () {
it('returns an error', function (done) {
assert.strictEqual(client.selected_db, undefined, 'default db should be undefined');
client.select(9999, function (err) {
assert.equal(err.code, 'ERR');
assert.equal(err.message, 'ERR invalid DB index');
@@ -79,21 +79,21 @@ describe("The 'select' method", function () {
});
});
describe("and no callback is specified", function () {
describe("with a valid db index", function () {
it("selects the appropriate database", function (done) {
assert.strictEqual(client.selected_db, undefined, "default db should be undefined");
describe('and no callback is specified', function () {
describe('with a valid db index', function () {
it('selects the appropriate database', function (done) {
assert.strictEqual(client.selected_db, undefined, 'default db should be undefined');
client.select(1);
setTimeout(function () {
assert.equal(client.selected_db, 1, "we should have selected the new valid DB");
assert.equal(client.selected_db, 1, 'we should have selected the new valid DB');
return done();
}, 100);
});
});
describe("with an invalid db index", function () {
it("emits an error when callback not provided", function (done) {
assert.strictEqual(client.selected_db, undefined, "default db should be undefined");
describe('with an invalid db index', function () {
it('emits an error when callback not provided', function (done) {
assert.strictEqual(client.selected_db, undefined, 'default db should be undefined');
client.on('error', function (err) {
assert.strictEqual(err.command, 'SELECT');
@@ -106,9 +106,9 @@ describe("The 'select' method", function () {
});
});
describe("reconnection occurs", function () {
it("selects the appropriate database after a reconnect", function (done) {
assert.strictEqual(client.selected_db, undefined, "default db should be undefined");
describe('reconnection occurs', function () {
it('selects the appropriate database after a reconnect', function (done) {
assert.strictEqual(client.selected_db, undefined, 'default db should be undefined');
client.select(3);
client.set('foo', 'bar', function () {
client.stream.destroy();

View File

@@ -1,16 +1,16 @@
'use strict';
var assert = require('assert');
var config = require("../lib/config");
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
var uuid = require('uuid');
describe("The 'set' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var key, value;
beforeEach(function () {
@@ -18,18 +18,18 @@ describe("The 'set' method", function () {
value = uuid.v4();
});
describe("when not connected", function () {
describe('when not connected', function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.quit();
});
client.on('end', done);
});
it("reports an error", function (done) {
it('reports an error', function (done) {
client.set(key, value, function (err, res) {
assert(err.message.match(/The connection has already been closed/));
done();
@@ -37,12 +37,12 @@ describe("The 'set' method", function () {
});
});
describe("when connected", function () {
describe('when connected', function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
done();
});
});
@@ -51,9 +51,9 @@ describe("The 'set' method", function () {
client.end(true);
});
describe("and a callback is specified", function () {
describe("with valid parameters", function () {
it("sets the value correctly", function (done) {
describe('and a callback is specified', function () {
describe('with valid parameters', function () {
it('sets the value correctly', function (done) {
client.SET(key, value, function (err, res) {
helper.isNotError()(err, res);
client.get(key, function (err, res) {
@@ -64,7 +64,7 @@ describe("The 'set' method", function () {
});
});
describe("reports an error with invalid parameters", function () {
describe('reports an error with invalid parameters', function () {
it("undefined 'key' and missing 'value' parameter", function (done) {
client.set(undefined, function (err, res) {
helper.isError()(err, null);
@@ -73,7 +73,7 @@ describe("The 'set' method", function () {
});
});
it("empty array as second parameter", function (done) {
it('empty array as second parameter', function (done) {
client.set('foo', [], function (err, res) {
assert.strictEqual(err.message, "ERR wrong number of arguments for 'set' command");
done();
@@ -82,26 +82,26 @@ describe("The 'set' method", function () {
});
});
describe("and no callback is specified", function () {
describe("with valid parameters", function () {
it("sets the value correctly", function (done) {
describe('and no callback is specified', function () {
describe('with valid parameters', function () {
it('sets the value correctly', function (done) {
client.set(key, value);
client.get(key, helper.isString(value, done));
});
it("sets the value correctly even if the callback is explicitly set to undefined", function (done) {
it('sets the value correctly even if the callback is explicitly set to undefined', function (done) {
client.set(key, value, undefined);
client.get(key, helper.isString(value, done));
});
it("sets the value correctly with the array syntax", function (done) {
it('sets the value correctly with the array syntax', function (done) {
client.set([key, value]);
client.get(key, helper.isString(value, done));
});
});
describe("with undefined 'key' and missing 'value' parameter", function () {
it("emits an error without callback", function (done) {
it('emits an error without callback', function (done) {
client.on('error', function (err) {
assert.equal(err.message, "ERR wrong number of arguments for 'set' command");
assert.equal(err.command, 'SET');
@@ -117,7 +117,7 @@ describe("The 'set' method", function () {
client.get('foo', helper.isString('null', done));
});
it("emit an error with only the key set", function (done) {
it('emit an error with only the key set', function (done) {
client.on('error', function (err) {
assert.equal(err.message, "ERR wrong number of arguments for 'set' command");
done();
@@ -126,8 +126,8 @@ describe("The 'set' method", function () {
client.set('foo');
});
it("emit an error without any parameters", function (done) {
client.once("error", function (err) {
it('emit an error without any parameters', function (done) {
client.once('error', function (err) {
assert.equal(err.message, "ERR wrong number of arguments for 'set' command");
assert.equal(err.command, 'SET');
done();

View File

@@ -1,27 +1,27 @@
'use strict';
var assert = require("assert");
var config = require("../lib/config");
var helper = require("../helper");
var assert = require('assert');
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
describe("The 'setex' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.flushdb(done);
});
});
it('sets a key with an expiry', function (done) {
client.setex(["setex key", "100", "setex val"], helper.isString("OK"));
var buffering = client.exists(["setex key"], helper.isNumber(1));
client.setex(['setex key', '100', 'setex val'], helper.isString('OK'));
var buffering = client.exists(['setex key'], helper.isNumber(1));
assert(typeof buffering === 'boolean');
client.ttl(['setex key'], function (err, ttl) {
assert(ttl > 0);

View File

@@ -1,19 +1,19 @@
'use strict';
var config = require("../lib/config");
var helper = require("../helper");
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
describe("The 'setnx' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.flushdb(done);
});
});

View File

@@ -1,20 +1,20 @@
'use strict';
var assert = require("assert");
var config = require("../lib/config");
var helper = require("../helper");
var assert = require('assert');
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
describe("The 'sinter' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.flushdb(done);
});
});

View File

@@ -1,20 +1,20 @@
'use strict';
var assert = require("assert");
var config = require("../lib/config");
var helper = require("../helper");
var assert = require('assert');
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
describe("The 'sinterstore' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.flushdb(done);
});
});

View File

@@ -1,19 +1,19 @@
'use strict';
var config = require("../lib/config");
var helper = require("../helper");
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
describe("The 'sismember' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.flushdb(done);
});
});

View File

@@ -1,34 +1,34 @@
'use strict';
var assert = require("assert");
var config = require("../lib/config");
var helper = require("../helper");
var assert = require('assert');
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
describe("The 'slowlog' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.flushdb(done);
});
});
it('logs operations in slowlog', function (done) {
client.config("set", "slowlog-log-slower-than", 0, helper.isString("OK"));
client.slowlog("reset", helper.isString("OK"));
client.set("foo", "bar", helper.isString("OK"));
client.get("foo", helper.isString("bar"));
client.SLOWLOG("get", function (err, res) {
client.config('set', 'slowlog-log-slower-than', 0, helper.isString('OK'));
client.slowlog('reset', helper.isString('OK'));
client.set('foo', 'bar', helper.isString('OK'));
client.get('foo', helper.isString('bar'));
client.SLOWLOG('get', function (err, res) {
assert.equal(res.length, 3);
assert.equal(res[0][3].length, 2);
assert.deepEqual(res[1][3], ["set", "foo", "bar"]);
assert.deepEqual(res[2][3], ["slowlog", "reset"]);
assert.deepEqual(res[1][3], ['set', 'foo', 'bar']);
assert.deepEqual(res[2][3], ['slowlog', 'reset']);
return done(err);
});
});

View File

@@ -1,20 +1,20 @@
'use strict';
var assert = require("assert");
var config = require("../lib/config");
var helper = require("../helper");
var assert = require('assert');
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
describe("The 'smembers' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.flushdb(done);
});
});

View File

@@ -1,19 +1,19 @@
'use strict';
var config = require("../lib/config");
var helper = require("../helper");
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
describe("The 'smove' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.flushdb(done);
});
});
@@ -25,7 +25,7 @@ describe("The 'smove' method", function () {
client.sismember('bar', 'x', helper.isNumber(1, done));
});
it("does not move a value if it does not exist in the first set", function (done) {
it('does not move a value if it does not exist in the first set', function (done) {
client.sadd('foo', 'x', helper.isNumber(1));
client.SMOVE('foo', 'bar', 'y', helper.isNumber(0));
client.sismember('foo', 'y', helper.isNumber(0));

View File

@@ -1,11 +1,11 @@
'use strict';
var assert = require("assert");
var config = require("../lib/config");
var helper = require("../helper");
var assert = require('assert');
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
function setupData(client, done) {
function setupData (client, done) {
client.rpush('y', 'd');
client.rpush('y', 'b');
client.rpush('y', 'a');
@@ -34,15 +34,15 @@ function setupData(client, done) {
describe("The 'sort' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("error", done);
client.once("connect", function () {
client.once('error', done);
client.once('connect', function () {
client.flushdb();
setupData(client, done);
});

View File

@@ -1,20 +1,20 @@
'use strict';
var assert = require("assert");
var config = require("../lib/config");
var helper = require("../helper");
var assert = require('assert');
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
describe("The 'spop' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.flushdb(done);
});
});

View File

@@ -1,20 +1,20 @@
'use strict';
var assert = require("assert");
var config = require("../lib/config");
var helper = require("../helper");
var assert = require('assert');
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
describe("The 'srem' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.flushdb(done);
});
});
@@ -30,33 +30,33 @@ describe("The 'srem' method", function () {
});
it('allows multiple values to be removed', function (done) {
client.sadd("set0", ["member0", "member1", "member2"], helper.isNumber(3));
client.SREM("set0", ["member1", "member2"], helper.isNumber(2));
client.smembers("set0", function (err, res) {
client.sadd('set0', ['member0', 'member1', 'member2'], helper.isNumber(3));
client.SREM('set0', ['member1', 'member2'], helper.isNumber(2));
client.smembers('set0', function (err, res) {
assert.strictEqual(res.length, 1);
assert.ok(~res.indexOf("member0"));
assert.ok(~res.indexOf('member0'));
return done(err);
});
});
it('allows multiple values to be removed with send_command', function (done) {
client.send_command('sadd', ['set0', 'member0', 'member1', 'member2'], helper.isNumber(3));
client.send_command('srem', ["set0", "member1", "member2"], helper.isNumber(2));
client.smembers("set0", function (err, res) {
client.send_command('srem', ['set0', 'member1', 'member2'], helper.isNumber(2));
client.smembers('set0', function (err, res) {
assert.strictEqual(res.length, 1);
assert.ok(~res.indexOf("member0"));
assert.ok(~res.indexOf('member0'));
return done(err);
});
});
it('handles a value missing from the set of values being removed', function (done) {
client.sadd(["set0", "member0", "member1", "member2"], helper.isNumber(3));
client.SREM(["set0", "member3", "member4"], helper.isNumber(0));
client.smembers("set0", function (err, res) {
client.sadd(['set0', 'member0', 'member1', 'member2'], helper.isNumber(3));
client.SREM(['set0', 'member3', 'member4'], helper.isNumber(0));
client.smembers('set0', function (err, res) {
assert.strictEqual(res.length, 3);
assert.ok(~res.indexOf("member0"));
assert.ok(~res.indexOf("member1"));
assert.ok(~res.indexOf("member2"));
assert.ok(~res.indexOf('member0'));
assert.ok(~res.indexOf('member1'));
assert.ok(~res.indexOf('member2'));
return done(err);
});
});

View File

@@ -1,20 +1,20 @@
'use strict';
var assert = require("assert");
var config = require("../lib/config");
var helper = require("../helper");
var assert = require('assert');
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
describe("The 'sunion' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.flushdb(done);
});
});

View File

@@ -1,20 +1,20 @@
'use strict';
var assert = require("assert");
var config = require("../lib/config");
var helper = require("../helper");
var assert = require('assert');
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
describe("The 'sunionstore' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.flushdb(done);
});
});

View File

@@ -1,29 +1,29 @@
'use strict';
var assert = require("assert");
var config = require("../lib/config");
var helper = require("../helper");
var assert = require('assert');
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
describe("The 'ttl' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.flushdb(done);
});
});
it('returns the current ttl on a key', function (done) {
client.set(["ttl key", "ttl val"], helper.isString("OK"));
client.expire(["ttl key", "100"], helper.isNumber(1));
client.set(['ttl key', 'ttl val'], helper.isString('OK'));
client.expire(['ttl key', '100'], helper.isNumber(1));
setTimeout(function () {
client.TTL(["ttl key"], function (err, ttl) {
client.TTL(['ttl key'], function (err, ttl) {
assert.ok(ttl > 50 && ttl <= 100);
return done(err);
});

View File

@@ -1,50 +1,50 @@
'use strict';
var config = require("../lib/config");
var helper = require("../helper");
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
describe("The 'type' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.flushdb(done);
});
});
it('reports string type', function (done) {
client.set(["string key", "should be a string"], helper.isString("OK"));
client.TYPE(["string key"], helper.isString("string", done));
client.set(['string key', 'should be a string'], helper.isString('OK'));
client.TYPE(['string key'], helper.isString('string', done));
});
it('reports list type', function (done) {
client.rpush(["list key", "should be a list"], helper.isNumber(1));
client.type(["list key"], helper.isString("list", done));
client.rpush(['list key', 'should be a list'], helper.isNumber(1));
client.type(['list key'], helper.isString('list', done));
});
it('reports set type', function (done) {
client.sadd(["set key", "should be a set"], helper.isNumber(1));
client.TYPE(["set key"], helper.isString("set", done));
client.sadd(['set key', 'should be a set'], helper.isNumber(1));
client.TYPE(['set key'], helper.isString('set', done));
});
it('reports zset type', function (done) {
client.zadd("zset key", ["10.0", "should be a zset"], helper.isNumber(1));
client.TYPE(["zset key"], helper.isString("zset", done));
client.zadd('zset key', ['10.0', 'should be a zset'], helper.isNumber(1));
client.TYPE(['zset key'], helper.isString('zset', done));
});
it('reports hash type', function (done) {
client.hset("hash key", "hashtest", "should be a hash", helper.isNumber(1));
client.TYPE(["hash key"], helper.isString("hash", done));
client.hset('hash key', 'hashtest', 'should be a hash', helper.isNumber(1));
client.TYPE(['hash key'], helper.isString('hash', done));
});
it('reports none for null key', function (done) {
client.TYPE("not here yet", helper.isString("none", done));
client.TYPE('not here yet', helper.isString('none', done));
});
afterEach(function () {

View File

@@ -1,22 +1,22 @@
'use strict';
var assert = require("assert");
var config = require("../lib/config");
var helper = require("../helper");
var assert = require('assert');
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
describe("The 'watch' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
var watched = 'foobar';
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.flushdb(done);
});
});
@@ -34,17 +34,17 @@ describe("The 'watch' method", function () {
});
it('successfully modifies other keys independently of transaction', function (done) {
client.set("unwatched", 200);
client.set('unwatched', 200);
client.set(watched, 0);
client.watch(watched);
client.incr(watched);
client.set(watched, 0);
client.watch(watched);
client.incr(watched);
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);
client.get('unwatched', function (err, reply) {
assert.equal(reply, 200, 'Expected 200, got ' + reply);
return done(err);
});
});

View File

@@ -1,36 +1,36 @@
'use strict';
var config = require("../lib/config");
var helper = require("../helper");
var config = require('../lib/config');
var helper = require('../helper');
var assert = require('assert');
var redis = config.redis;
describe("The 'zadd' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.flushdb(done);
});
});
it('reports an error', function (done) {
if (helper.redisProcess().spawnFailed()) this.skip();
client.zadd('infinity', [+'5t', "should not be possible"], helper.isError(done));
client.zadd('infinity', [+'5t', 'should not be possible'], helper.isError(done));
});
it('return inf / -inf', function (done) {
if (helper.redisProcess().spawnFailed()) this.skip();
helper.serverVersionAtLeast.call(this, client, [3, 0, 2]);
client.zadd('infinity', [+Infinity, "should be inf"], helper.isNumber(1));
client.zadd('infinity', [+Infinity, 'should be inf'], helper.isNumber(1));
client.zadd('infinity', ['inf', 'should be also be inf'], helper.isNumber(1));
client.zadd('infinity', -Infinity, "should be negative inf", helper.isNumber(1));
client.zadd('infinity', [99999999999999999999999, "should not be inf"], helper.isNumber(1));
client.zadd('infinity', -Infinity, 'should be negative inf', helper.isNumber(1));
client.zadd('infinity', [99999999999999999999999, 'should not be inf'], helper.isNumber(1));
client.zrange('infinity', 0, -1, 'WITHSCORES', function (err, res) {
assert.equal(res[5], 'inf');
assert.equal(res[1], '-inf');

View File

@@ -7,14 +7,14 @@ var redis = config.redis;
describe("The 'zscan' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.flushdb(done);
});
});
@@ -24,14 +24,14 @@ describe("The 'zscan' method", function () {
helper.serverVersionAtLeast.call(this, client, [2, 8, 0]);
var hash = {};
var set = [];
var zset = ["zset:1"];
var zset = ['zset:1'];
for (var i = 0; i < 500; i++) {
hash["key_" + i] = "value_" + i;
set.push("member_" + i);
zset.push(i, "z_member_" + i);
hash['key_' + i] = 'value_' + i;
set.push('member_' + i);
zset.push(i, 'z_member_' + i);
}
client.hmset("hash:1", hash);
client.sadd("set:1", set);
client.hmset('hash:1', hash);
client.sadd('set:1', set);
client.zadd(zset);
client.zscan('zset:1', 0, 'MATCH', '*', 'COUNT', 500, function (err, res) {
assert(!err);

View File

@@ -1,20 +1,20 @@
'use strict';
var config = require("../lib/config");
var helper = require("../helper");
var config = require('../lib/config');
var helper = require('../helper');
var assert = require('assert');
var redis = config.redis;
describe("The 'zscore' method", function () {
helper.allTests(function(parser, ip, args) {
helper.allTests(function (parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
describe('using ' + parser + ' and ' + ip, function () {
var client;
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once("ready", function () {
client.once('ready', function () {
client.flushdb(done);
});
});