You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-04 15:02:09 +03:00
Replace jshint with eslint and add lots of rules
Fix eslint errors accordingly
This commit is contained in:
108
.eslintrc
Normal file
108
.eslintrc
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
env:
|
||||||
|
node: true
|
||||||
|
es6: false
|
||||||
|
|
||||||
|
rules:
|
||||||
|
# Possible Errors
|
||||||
|
# http://eslint.org/docs/rules/#possible-errors
|
||||||
|
comma-dangle: [2, "only-multiline"]
|
||||||
|
no-constant-condition: 2
|
||||||
|
no-control-regex: 2
|
||||||
|
no-debugger: 2
|
||||||
|
no-dupe-args: 2
|
||||||
|
no-dupe-keys: 2
|
||||||
|
no-duplicate-case: 2
|
||||||
|
no-empty: 2
|
||||||
|
no-empty-character-class: 2
|
||||||
|
no-ex-assign: 2
|
||||||
|
no-extra-boolean-cast : 2
|
||||||
|
no-extra-parens: [2, "functions"]
|
||||||
|
no-extra-semi: 2
|
||||||
|
no-func-assign: 2
|
||||||
|
no-invalid-regexp: 2
|
||||||
|
no-irregular-whitespace: 2
|
||||||
|
no-negated-in-lhs: 2
|
||||||
|
no-obj-calls: 2
|
||||||
|
no-regex-spaces: 2
|
||||||
|
no-sparse-arrays: 2
|
||||||
|
no-inner-declarations: 2
|
||||||
|
no-unexpected-multiline: 2
|
||||||
|
no-unreachable: 2
|
||||||
|
use-isnan: 2
|
||||||
|
valid-typeof: 2
|
||||||
|
|
||||||
|
# Best Practices
|
||||||
|
# http://eslint.org/docs/rules/#best-practices
|
||||||
|
array-callback-return: 2
|
||||||
|
block-scoped-var: 2
|
||||||
|
dot-notation: 2
|
||||||
|
eqeqeq: 2
|
||||||
|
no-else-return: 2
|
||||||
|
no-extend-native: 2
|
||||||
|
no-floating-decimal: 2
|
||||||
|
no-extra-bind: 2
|
||||||
|
no-fallthrough: 2
|
||||||
|
no-labels: 2
|
||||||
|
no-lone-blocks: 2
|
||||||
|
no-loop-func: 2
|
||||||
|
no-multi-spaces: 2
|
||||||
|
no-multi-str: 2
|
||||||
|
no-native-reassign: 2
|
||||||
|
no-new-wrappers: 2
|
||||||
|
no-octal: 2
|
||||||
|
no-proto: 2
|
||||||
|
no-redeclare: 2
|
||||||
|
no-return-assign: 2
|
||||||
|
no-self-assign: 2
|
||||||
|
no-self-compare: 2
|
||||||
|
no-sequences: 2
|
||||||
|
no-throw-literal: 2
|
||||||
|
no-useless-call: 2
|
||||||
|
no-useless-concat: 2
|
||||||
|
no-useless-escape: 2
|
||||||
|
no-void: 2
|
||||||
|
no-unmodified-loop-condition: 2
|
||||||
|
yoda: 2
|
||||||
|
|
||||||
|
# Strict Mode
|
||||||
|
# http://eslint.org/docs/rules/#strict-mode
|
||||||
|
strict: [2, "global"]
|
||||||
|
|
||||||
|
# Variables
|
||||||
|
# http://eslint.org/docs/rules/#variables
|
||||||
|
no-delete-var: 2
|
||||||
|
no-shadow-restricted-names: 2
|
||||||
|
no-undef: 2
|
||||||
|
no-unused-vars: [2, {"args": "none"}]
|
||||||
|
|
||||||
|
# http://eslint.org/docs/rules/#nodejs-and-commonjs
|
||||||
|
no-mixed-requires: 2
|
||||||
|
no-new-require: 2
|
||||||
|
no-path-concat: 2
|
||||||
|
|
||||||
|
# Stylistic Issues
|
||||||
|
# http://eslint.org/docs/rules/#stylistic-issues
|
||||||
|
comma-spacing: 2
|
||||||
|
eol-last: 2
|
||||||
|
indent: [2, 4, {SwitchCase: 2}]
|
||||||
|
keyword-spacing: 2
|
||||||
|
max-len: [2, 200, 2]
|
||||||
|
new-parens: 2
|
||||||
|
no-mixed-spaces-and-tabs: 2
|
||||||
|
no-multiple-empty-lines: [2, {max: 2}]
|
||||||
|
no-trailing-spaces: 2
|
||||||
|
quotes: [2, "single", "avoid-escape"]
|
||||||
|
semi: 2
|
||||||
|
space-before-blocks: [2, "always"]
|
||||||
|
space-before-function-paren: [2, "always"]
|
||||||
|
space-in-parens: [2, "never"]
|
||||||
|
space-infix-ops: 2
|
||||||
|
space-unary-ops: 2
|
||||||
|
|
||||||
|
globals:
|
||||||
|
it: true
|
||||||
|
describe: true
|
||||||
|
before: true
|
||||||
|
after: true
|
||||||
|
beforeEach: true
|
||||||
|
afterEach: true
|
27
.jshintrc
27
.jshintrc
@@ -1,27 +0,0 @@
|
|||||||
{
|
|
||||||
"eqeqeq": true, // Prohibits the use of == and != in favor of === and !==
|
|
||||||
"noarg": true, // Prohibit use of `arguments.caller` and `arguments.callee`
|
|
||||||
"undef": true, // Require all non-global variables be declared before they are used.
|
|
||||||
"unused": "vars", // Warn unused variables, but not unused params
|
|
||||||
"strict": true, // Require `use strict` pragma in every file.
|
|
||||||
"nonbsp": true, // don't allow non utf-8 pages to break
|
|
||||||
"forin": true, // don't allow not filtert for in loops
|
|
||||||
"freeze": true, // prohibit overwriting prototypes of native objects
|
|
||||||
"nonew": true, // prohibit use of constructors with new when not assigning to a variable
|
|
||||||
"maxdepth": 6,
|
|
||||||
"latedef": true,
|
|
||||||
"maxparams": 5,
|
|
||||||
|
|
||||||
// Environment options
|
|
||||||
"node": true, // Enable globals available when code is running inside of the NodeJS runtime environment.
|
|
||||||
"mocha": true,
|
|
||||||
|
|
||||||
// Relaxing options
|
|
||||||
"boss": true, // Accept statements like `while (key = keys.pop()) {}`
|
|
||||||
|
|
||||||
"overrides": {
|
|
||||||
"examples/*.js": {
|
|
||||||
"unused": false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var redis = require('redis'),
|
var redis = require('redis');
|
||||||
client = redis.createClient();
|
|
||||||
|
|
||||||
// The client stashes the password and will reauthenticate on every connect.
|
// The client stashes the password and will reauthenticate on every connect.
|
||||||
client.auth('somepass');
|
redis.createClient({
|
||||||
|
password: 'somepass'
|
||||||
|
});
|
||||||
|
@@ -1,8 +1,9 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var redis = require('../index'),
|
var redis = require('../index');
|
||||||
client = redis.createClient(),
|
var client = redis.createClient();
|
||||||
remaining_ops = 100000, paused = false;
|
var remaining_ops = 100000;
|
||||||
|
var paused = false;
|
||||||
|
|
||||||
function op () {
|
function op () {
|
||||||
if (remaining_ops <= 0) {
|
if (remaining_ops <= 0) {
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var redis = require('../index'),
|
var redis = require('../index');
|
||||||
client = redis.createClient();
|
var client = redis.createClient();
|
||||||
|
|
||||||
client.eval('return 100.5', 0, function (err, res) {
|
client.eval('return 100.5', 0, function (err, res) {
|
||||||
console.dir(err);
|
console.dir(err);
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var redis = require('redis'),
|
var redis = require('redis');
|
||||||
client = redis.createClient();
|
var client = redis.createClient();
|
||||||
|
|
||||||
// Extend the RedisClient prototype to add a custom method
|
// Extend the RedisClient prototype to add a custom method
|
||||||
// This one converts the results from 'INFO' into a JavaScript Object
|
// This one converts the results from 'INFO' into a JavaScript Object
|
||||||
|
@@ -2,13 +2,13 @@
|
|||||||
|
|
||||||
// Read a file from disk, store it in Redis, then read it back from Redis.
|
// Read a file from disk, store it in Redis, then read it back from Redis.
|
||||||
|
|
||||||
var redis = require('redis'),
|
var redis = require('redis');
|
||||||
client = redis.createClient({
|
var client = redis.createClient({
|
||||||
return_buffers: true
|
return_buffers: true
|
||||||
}),
|
});
|
||||||
fs = require('fs'),
|
var fs = require('fs');
|
||||||
assert = require('assert'),
|
var assert = require('assert');
|
||||||
filename = 'grumpyCat.jpg';
|
var filename = 'grumpyCat.jpg';
|
||||||
|
|
||||||
// Get the file I use for testing like this:
|
// Get the file I use for testing like this:
|
||||||
// curl http://media4.popsugar-assets.com/files/2014/08/08/878/n/1922507/caef16ec354ca23b_thumb_temp_cover_file32304521407524949.xxxlarge/i/Funny-Cat-GIFs.jpg -o grumpyCat.jpg
|
// curl http://media4.popsugar-assets.com/files/2014/08/08/878/n/1922507/caef16ec354ca23b_thumb_temp_cover_file32304521407524949.xxxlarge/i/Funny-Cat-GIFs.jpg -o grumpyCat.jpg
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var client = require('../index').createClient(),
|
var client = require('../index').createClient();
|
||||||
util = require('util');
|
var util = require('util');
|
||||||
|
|
||||||
client.monitor(function (err, res) {
|
client.monitor(function (err, res) {
|
||||||
console.log('Entering monitoring mode.');
|
console.log('Entering monitoring mode.');
|
||||||
|
@@ -1,7 +1,8 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var redis = require('redis'),
|
var redis = require('redis');
|
||||||
client = redis.createClient(), set_size = 20;
|
var client = redis.createClient();
|
||||||
|
var set_size = 20;
|
||||||
|
|
||||||
client.sadd('bigset', 'a member');
|
client.sadd('bigset', 'a member');
|
||||||
client.sadd('bigset', 'another member');
|
client.sadd('bigset', 'another member');
|
||||||
|
@@ -1,10 +1,10 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var redis = require('redis'),
|
var redis = require('redis');
|
||||||
client = redis.createClient(), multi;
|
var client = redis.createClient();
|
||||||
|
|
||||||
// start a separate command queue for multi
|
// start a separate command queue for multi
|
||||||
multi = client.multi();
|
var multi = client.multi();
|
||||||
multi.incr('incr thing', redis.print);
|
multi.incr('incr thing', redis.print);
|
||||||
multi.incr('incr other thing', redis.print);
|
multi.incr('incr other thing', redis.print);
|
||||||
|
|
||||||
|
@@ -1,11 +1,11 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var redis = require('redis'),
|
var redis = require('redis');
|
||||||
client1 = redis.createClient(),
|
var client1 = redis.createClient();
|
||||||
client2 = redis.createClient(),
|
var client2 = redis.createClient();
|
||||||
client3 = redis.createClient(),
|
var client3 = redis.createClient();
|
||||||
client4 = redis.createClient(),
|
var client4 = redis.createClient();
|
||||||
msg_count = 0;
|
var msg_count = 0;
|
||||||
|
|
||||||
client1.on('psubscribe', function (pattern, count) {
|
client1.on('psubscribe', function (pattern, count) {
|
||||||
console.log('client1 psubscribed to ' + pattern + ', ' + count + ' total subscriptions');
|
console.log('client1 psubscribed to ' + pattern + ', ' + count + ' total subscriptions');
|
||||||
@@ -23,7 +23,7 @@ client1.on('punsubscribe', function (pattern, count) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
client1.on('pmessage', function (pattern, channel, message) {
|
client1.on('pmessage', function (pattern, channel, message) {
|
||||||
console.log('('+ pattern +')' + ' client1 received message on ' + channel + ': ' + message);
|
console.log('(' + pattern + ') client1 received message on ' + channel + ': ' + message);
|
||||||
msg_count += 1;
|
msg_count += 1;
|
||||||
if (msg_count === 3) {
|
if (msg_count === 3) {
|
||||||
client1.punsubscribe();
|
client1.punsubscribe();
|
||||||
|
@@ -1,8 +1,9 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var redis = require('redis'),
|
var redis = require('redis');
|
||||||
client1 = redis.createClient(), msg_count = 0,
|
var client1 = redis.createClient();
|
||||||
client2 = redis.createClient();
|
var msg_count = 0;
|
||||||
|
var client2 = redis.createClient();
|
||||||
|
|
||||||
// Most clients probably don't do much on 'subscribe'. This example uses it to coordinate things within one program.
|
// Most clients probably don't do much on 'subscribe'. This example uses it to coordinate things within one program.
|
||||||
client1.on('subscribe', function (channel, count) {
|
client1.on('subscribe', function (channel, count) {
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var redis = require('redis'),
|
var redis = require('redis');
|
||||||
client = redis.createClient();
|
var client = redis.createClient();
|
||||||
|
|
||||||
var cursor = '0';
|
var cursor = '0';
|
||||||
|
|
||||||
@@ -48,3 +48,4 @@ function scan() {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
scan();
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var redis = require('redis'),
|
var redis = require('redis');
|
||||||
client = redis.createClient();
|
var client = redis.createClient();
|
||||||
|
|
||||||
client.on('error', function (err) {
|
client.on('error', function (err) {
|
||||||
console.log('error event - ' + client.host + ':' + client.port + ' - ' + err);
|
console.log('error event - ' + client.host + ':' + client.port + ' - ' + err);
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var redis = require('redis'),
|
var redis = require('redis');
|
||||||
client = redis.createClient();
|
var client = redis.createClient();
|
||||||
|
|
||||||
client.sadd('mylist', 1);
|
client.sadd('mylist', 1);
|
||||||
client.sadd('mylist', 2);
|
client.sadd('mylist', 2);
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var redis = require('redis'),
|
var redis = require('redis');
|
||||||
client = redis.createClient('/tmp/redis.sock'),
|
var client = redis.createClient('/tmp/redis.sock');
|
||||||
profiler = require('v8-profiler');
|
var profiler = require('v8-profiler');
|
||||||
|
|
||||||
client.on('connect', function () {
|
client.on('connect', function () {
|
||||||
console.log('Got Unix socket connection.');
|
console.log('Got Unix socket connection.');
|
||||||
@@ -28,4 +28,5 @@ function done() {
|
|||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
console.log('Taking snapshot.');
|
console.log('Taking snapshot.');
|
||||||
profiler.takeSnapshot();
|
profiler.takeSnapshot();
|
||||||
|
done();
|
||||||
}, 5000);
|
}, 5000);
|
||||||
|
@@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
// A simple web server that generates dyanmic content based on responses from Redis
|
// A simple web server that generates dyanmic content based on responses from Redis
|
||||||
|
|
||||||
var http = require('http'), server,
|
var http = require('http');
|
||||||
redis_client = require('redis').createClient();
|
var redis_client = require('redis').createClient();
|
||||||
|
|
||||||
server = http.createServer(function (request, response) {
|
http.createServer(function (request, response) { // The server
|
||||||
response.writeHead(200, {
|
response.writeHead(200, {
|
||||||
'Content-Type': 'text/plain'
|
'Content-Type': 'text/plain'
|
||||||
});
|
});
|
||||||
|
2
index.js
2
index.js
@@ -620,7 +620,7 @@ RedisClient.prototype.emit_idle = function () {
|
|||||||
function normal_reply (self, reply) {
|
function normal_reply (self, reply) {
|
||||||
var command_obj = self.command_queue.shift();
|
var command_obj = self.command_queue.shift();
|
||||||
if (typeof command_obj.callback === 'function') {
|
if (typeof command_obj.callback === 'function') {
|
||||||
if ('exec' !== command_obj.command) {
|
if (command_obj.command !== 'exec') {
|
||||||
reply = self.handle_reply(reply, command_obj.command, command_obj.buffer_args);
|
reply = self.handle_reply(reply, command_obj.command, command_obj.buffer_args);
|
||||||
}
|
}
|
||||||
command_obj.callback(null, reply);
|
command_obj.callback(null, reply);
|
||||||
|
@@ -173,7 +173,6 @@ Multi.prototype.exec = Multi.prototype.EXEC = Multi.prototype.exec_batch = funct
|
|||||||
var len = self.queue.length;
|
var len = self.queue.length;
|
||||||
var index = 0;
|
var index = 0;
|
||||||
var args;
|
var args;
|
||||||
var args_len = 1;
|
|
||||||
var callback_without_own_cb = function (err, res) {
|
var callback_without_own_cb = function (err, res) {
|
||||||
if (err) {
|
if (err) {
|
||||||
self.results.push(err);
|
self.results.push(err);
|
||||||
@@ -203,7 +202,6 @@ Multi.prototype.exec = Multi.prototype.EXEC = Multi.prototype.exec_batch = funct
|
|||||||
while (args = self.queue.shift()) {
|
while (args = self.queue.shift()) {
|
||||||
var command = args[0];
|
var command = args[0];
|
||||||
var cb;
|
var cb;
|
||||||
args_len = args[1].length - 1;
|
|
||||||
if (typeof args[2] === 'function') {
|
if (typeof args[2] === 'function') {
|
||||||
cb = batch_callback(self, args[2], index);
|
cb = batch_callback(self, args[2], index);
|
||||||
} else {
|
} else {
|
||||||
|
@@ -22,7 +22,7 @@
|
|||||||
"benchmark": "node benchmarks/multi_bench.js",
|
"benchmark": "node benchmarks/multi_bench.js",
|
||||||
"test": "nyc --cache mocha ./test/*.js ./test/commands/*.js --timeout=8000",
|
"test": "nyc --cache mocha ./test/*.js ./test/commands/*.js --timeout=8000",
|
||||||
"pretest": "optional-dev-dependency hiredis",
|
"pretest": "optional-dev-dependency hiredis",
|
||||||
"posttest": "jshint ."
|
"posttest": "eslint . --fix"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"double-ended-queue": "^2.1.0-0",
|
"double-ended-queue": "^2.1.0-0",
|
||||||
@@ -36,7 +36,7 @@
|
|||||||
"bluebird": "^3.0.2",
|
"bluebird": "^3.0.2",
|
||||||
"coveralls": "^2.11.2",
|
"coveralls": "^2.11.2",
|
||||||
"intercept-stdout": "~0.1.2",
|
"intercept-stdout": "~0.1.2",
|
||||||
"jshint": "^2.8.0",
|
"eslint": "^2.5.0",
|
||||||
"metrics": "^0.1.9",
|
"metrics": "^0.1.9",
|
||||||
"mocha": "^2.3.2",
|
"mocha": "^2.3.2",
|
||||||
"nyc": "^6.0.0",
|
"nyc": "^6.0.0",
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require("assert");
|
var assert = require('assert');
|
||||||
var config = require("./lib/config");
|
var config = require('./lib/config');
|
||||||
var helper = require('./helper');
|
var helper = require('./helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
@@ -10,7 +10,7 @@ if (process.platform === 'win32') {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("client authentication", function () {
|
describe('client authentication', function () {
|
||||||
before(function (done) {
|
before(function (done) {
|
||||||
helper.stopRedis(function () {
|
helper.stopRedis(function () {
|
||||||
helper.startRedis('./conf/password.conf', done);
|
helper.startRedis('./conf/password.conf', done);
|
||||||
@@ -21,7 +21,7 @@ describe("client authentication", function () {
|
|||||||
allConnections: true
|
allConnections: true
|
||||||
}, function (parser, ip, args) {
|
}, function (parser, ip, args) {
|
||||||
|
|
||||||
describe("using " + parser + " and " + ip, function () {
|
describe('using ' + parser + ' and ' + ip, function () {
|
||||||
var auth = 'porkchopsandwiches';
|
var auth = 'porkchopsandwiches';
|
||||||
var client = null;
|
var client = null;
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ describe("client authentication", function () {
|
|||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.auth(auth, function (err, res) {
|
client.auth(auth, function (err, res) {
|
||||||
assert.strictEqual(null, err);
|
assert.strictEqual(null, err);
|
||||||
assert.strictEqual("OK", res.toString());
|
assert.strictEqual('OK', res.toString());
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -67,7 +67,7 @@ describe("client authentication", function () {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
it("emits error when auth is bad without callback", function (done) {
|
it('emits error when auth is bad without callback', function (done) {
|
||||||
if (helper.redisProcess().spawnFailed()) this.skip();
|
if (helper.redisProcess().spawnFailed()) this.skip();
|
||||||
|
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
@@ -81,7 +81,7 @@ describe("client authentication", function () {
|
|||||||
client.auth(auth + 'bad');
|
client.auth(auth + 'bad');
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns an error when auth is bad (empty string) with a callback", function (done) {
|
it('returns an error when auth is bad (empty string) with a callback', function (done) {
|
||||||
if (helper.redisProcess().spawnFailed()) this.skip();
|
if (helper.redisProcess().spawnFailed()) this.skip();
|
||||||
|
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
@@ -99,7 +99,7 @@ describe("client authentication", function () {
|
|||||||
|
|
||||||
var end = helper.callFuncAfter(done, 2);
|
var end = helper.callFuncAfter(done, 2);
|
||||||
client = redis.createClient('redis://:' + auth + '@' + config.HOST[ip] + ':' + config.PORT);
|
client = redis.createClient('redis://:' + auth + '@' + config.HOST[ip] + ':' + config.PORT);
|
||||||
client.on("ready", function () {
|
client.on('ready', function () {
|
||||||
end();
|
end();
|
||||||
});
|
});
|
||||||
// The info command may be used while loading but not if not yet authenticated
|
// The info command may be used while loading but not if not yet authenticated
|
||||||
@@ -116,7 +116,7 @@ describe("client authentication", function () {
|
|||||||
assert.strictEqual(client.options.db, '2');
|
assert.strictEqual(client.options.db, '2');
|
||||||
assert.strictEqual(client.options.password, auth);
|
assert.strictEqual(client.options.password, auth);
|
||||||
assert.strictEqual(client.auth_pass, auth);
|
assert.strictEqual(client.auth_pass, auth);
|
||||||
client.on("ready", function () {
|
client.on('ready', function () {
|
||||||
// Set a key so the used database is returned in the info command
|
// Set a key so the used database is returned in the info command
|
||||||
client.set('foo', 'bar');
|
client.set('foo', 'bar');
|
||||||
client.get('foo');
|
client.get('foo');
|
||||||
@@ -137,7 +137,7 @@ describe("client authentication", function () {
|
|||||||
auth_pass: auth
|
auth_pass: auth
|
||||||
});
|
});
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.on("ready", done);
|
client.on('ready', done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('allows auth and no_ready_check to be provided as config option for client', function (done) {
|
it('allows auth and no_ready_check to be provided as config option for client', function (done) {
|
||||||
@@ -148,7 +148,7 @@ describe("client authentication", function () {
|
|||||||
no_ready_check: true
|
no_ready_check: true
|
||||||
});
|
});
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.on("ready", done);
|
client.on('ready', done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('allows auth to be provided post-hoc with auth method', function (done) {
|
it('allows auth to be provided post-hoc with auth method', function (done) {
|
||||||
@@ -157,7 +157,7 @@ describe("client authentication", function () {
|
|||||||
var args = config.configureClient(parser, ip);
|
var args = config.configureClient(parser, ip);
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.auth(auth);
|
client.auth(auth);
|
||||||
client.on("ready", done);
|
client.on('ready', done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('reconnects with appropriate authentication', function (done) {
|
it('reconnects with appropriate authentication', function (done) {
|
||||||
@@ -165,7 +165,7 @@ describe("client authentication", function () {
|
|||||||
|
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.auth(auth);
|
client.auth(auth);
|
||||||
client.on("ready", function () {
|
client.on('ready', function () {
|
||||||
if (this.times_connected === 1) {
|
if (this.times_connected === 1) {
|
||||||
client.stream.destroy();
|
client.stream.destroy();
|
||||||
} else {
|
} else {
|
||||||
@@ -211,7 +211,7 @@ describe("client authentication", function () {
|
|||||||
auth_pass: auth
|
auth_pass: auth
|
||||||
});
|
});
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.on("ready", function () {
|
client.on('ready', function () {
|
||||||
client.auth(auth, helper.isString('OK', done));
|
client.auth(auth, helper.isString('OK', done));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -223,7 +223,7 @@ describe("client authentication", function () {
|
|||||||
no_ready_check: true
|
no_ready_check: true
|
||||||
});
|
});
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.on("ready", function () {
|
client.on('ready', function () {
|
||||||
client.set('foo', 'bar', function (err, res) {
|
client.set('foo', 'bar', function (err, res) {
|
||||||
assert.equal(err.message, 'NOAUTH Authentication required.');
|
assert.equal(err.message, 'NOAUTH Authentication required.');
|
||||||
assert.equal(err.code, 'NOAUTH');
|
assert.equal(err.code, 'NOAUTH');
|
||||||
@@ -236,7 +236,7 @@ describe("client authentication", function () {
|
|||||||
it('does not allow auth to be provided post-hoc with auth method if not authenticated before', function (done) {
|
it('does not allow auth to be provided post-hoc with auth method if not authenticated before', function (done) {
|
||||||
if (helper.redisProcess().spawnFailed()) this.skip();
|
if (helper.redisProcess().spawnFailed()) this.skip();
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.on("error", function (err) {
|
client.on('error', function (err) {
|
||||||
assert.equal(err.code, 'NOAUTH');
|
assert.equal(err.code, 'NOAUTH');
|
||||||
assert.equal(err.message, 'Ready check failed: NOAUTH Authentication required.');
|
assert.equal(err.message, 'Ready check failed: NOAUTH Authentication required.');
|
||||||
assert.equal(err.command, 'INFO');
|
assert.equal(err.command, 'INFO');
|
||||||
@@ -250,7 +250,7 @@ describe("client authentication", function () {
|
|||||||
password: 'wrong_password',
|
password: 'wrong_password',
|
||||||
parser: parser
|
parser: parser
|
||||||
});
|
});
|
||||||
client.once("error", function (err) {
|
client.once('error', function (err) {
|
||||||
assert.strictEqual(err.message, 'ERR invalid password');
|
assert.strictEqual(err.message, 'ERR invalid password');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@@ -1,35 +1,28 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
var config = require("./lib/config");
|
var config = require('./lib/config');
|
||||||
var helper = require('./helper');
|
var helper = require('./helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
var uuid = require('uuid');
|
|
||||||
|
|
||||||
describe("The 'batch' method", function () {
|
describe("The 'batch' 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 () {
|
describe('when not connected', function () {
|
||||||
key = uuid.v4();
|
|
||||||
value = uuid.v4();
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("when not connected", function () {
|
|
||||||
var client;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("connect", function () {
|
client.once('connect', function () {
|
||||||
client.quit();
|
client.quit();
|
||||||
});
|
});
|
||||||
client.on('end', done);
|
client.on('end', done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns an empty array", function (done) {
|
it('returns an empty array', function (done) {
|
||||||
var batch = client.batch();
|
var batch = client.batch();
|
||||||
batch.exec(function (err, res) {
|
batch.exec(function (err, res) {
|
||||||
assert.strictEqual(err, null);
|
assert.strictEqual(err, null);
|
||||||
@@ -38,19 +31,19 @@ describe("The 'batch' method", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns an empty array if promisified", function () {
|
it('returns an empty array if promisified', function () {
|
||||||
return client.batch().execAsync().then(function (res) {
|
return client.batch().execAsync().then(function (res) {
|
||||||
assert.strictEqual(res.length, 0);
|
assert.strictEqual(res.length, 0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when connected", function () {
|
describe('when connected', function () {
|
||||||
var client;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.flushdb(function (err) {
|
client.flushdb(function (err) {
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
@@ -61,7 +54,7 @@ describe("The 'batch' method", function () {
|
|||||||
client.end(true);
|
client.end(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns an empty array and keep the execution order in takt", function (done) {
|
it('returns an empty array and keep the execution order in takt', function (done) {
|
||||||
var called = false;
|
var called = false;
|
||||||
client.set('foo', 'bar', function (err, res) {
|
client.set('foo', 'bar', function (err, res) {
|
||||||
called = true;
|
called = true;
|
||||||
@@ -75,19 +68,19 @@ describe("The 'batch' method", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("runs normal calls inbetween batch", function (done) {
|
it('runs normal calls inbetween batch', function (done) {
|
||||||
var batch = client.batch();
|
var batch = client.batch();
|
||||||
batch.set("m1", "123");
|
batch.set('m1', '123');
|
||||||
client.set('m2', '456', done);
|
client.set('m2', '456', done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns an empty array if promisified", function () {
|
it('returns an empty array if promisified', function () {
|
||||||
return client.batch().execAsync().then(function (res) {
|
return client.batch().execAsync().then(function (res) {
|
||||||
assert.strictEqual(res.length, 0);
|
assert.strictEqual(res.length, 0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns an empty result array", function (done) {
|
it('returns an empty result array', function (done) {
|
||||||
var batch = client.batch();
|
var batch = client.batch();
|
||||||
var async = true;
|
var async = true;
|
||||||
var notBuffering = batch.exec(function (err, res) {
|
var notBuffering = batch.exec(function (err, res) {
|
||||||
@@ -103,18 +96,18 @@ describe("The 'batch' method", function () {
|
|||||||
it('fail individually when one command fails using chaining notation', function (done) {
|
it('fail individually when one command fails using chaining notation', function (done) {
|
||||||
var batch1, batch2;
|
var batch1, batch2;
|
||||||
batch1 = client.batch();
|
batch1 = client.batch();
|
||||||
batch1.mset("batchfoo", "10", "batchbar", "20", helper.isString("OK"));
|
batch1.mset('batchfoo', '10', 'batchbar', '20', helper.isString('OK'));
|
||||||
|
|
||||||
// Provoke an error at queue time
|
// Provoke an error at queue time
|
||||||
batch1.set("foo2", helper.isError());
|
batch1.set('foo2', helper.isError());
|
||||||
batch1.incr("batchfoo");
|
batch1.incr('batchfoo');
|
||||||
batch1.incr("batchbar");
|
batch1.incr('batchbar');
|
||||||
batch1.exec(function () {
|
batch1.exec(function () {
|
||||||
// Confirm that the previous command, while containing an error, still worked.
|
// Confirm that the previous command, while containing an error, still worked.
|
||||||
batch2 = client.batch();
|
batch2 = client.batch();
|
||||||
batch2.get('foo2', helper.isNull());
|
batch2.get('foo2', helper.isNull());
|
||||||
batch2.incr("batchbar", helper.isNumber(22));
|
batch2.incr('batchbar', helper.isNumber(22));
|
||||||
batch2.incr("batchfoo", helper.isNumber(12));
|
batch2.incr('batchfoo', helper.isNumber(12));
|
||||||
batch2.exec(function (err, replies) {
|
batch2.exec(function (err, replies) {
|
||||||
assert.strictEqual(null, replies[0]);
|
assert.strictEqual(null, replies[0]);
|
||||||
assert.strictEqual(22, replies[1]);
|
assert.strictEqual(22, replies[1]);
|
||||||
@@ -130,12 +123,12 @@ describe("The 'batch' method", function () {
|
|||||||
done(err);
|
done(err);
|
||||||
});
|
});
|
||||||
batch1 = client.batch();
|
batch1 = client.batch();
|
||||||
batch1.mset("batchfoo", "10", "batchbar", "20", helper.isString("OK"));
|
batch1.mset('batchfoo', '10', 'batchbar', '20', helper.isString('OK'));
|
||||||
|
|
||||||
// Provoke an error at queue time
|
// Provoke an error at queue time
|
||||||
batch1.set("foo2");
|
batch1.set('foo2');
|
||||||
batch1.incr("batchfoo");
|
batch1.incr('batchfoo');
|
||||||
batch1.incr("batchbar");
|
batch1.incr('batchbar');
|
||||||
batch1.exec(function (err, res) {
|
batch1.exec(function (err, res) {
|
||||||
assert.strictEqual(res[1].command, 'SET');
|
assert.strictEqual(res[1].command, 'SET');
|
||||||
assert.strictEqual(res[1].code, 'ERR');
|
assert.strictEqual(res[1].code, 'ERR');
|
||||||
@@ -146,45 +139,45 @@ describe("The 'batch' method", function () {
|
|||||||
it('fail individually when one command in an array of commands fails', function (done) {
|
it('fail individually when one command in an array of commands fails', function (done) {
|
||||||
// test nested batch-bulk replies
|
// test nested batch-bulk replies
|
||||||
client.batch([
|
client.batch([
|
||||||
["mget", "batchfoo", "batchbar", function (err, res) {
|
['mget', 'batchfoo', 'batchbar', function (err, res) {
|
||||||
assert.strictEqual(2, res.length);
|
assert.strictEqual(2, res.length);
|
||||||
assert.strictEqual(0, +res[0]);
|
assert.strictEqual(0, +res[0]);
|
||||||
assert.strictEqual(0, +res[1]);
|
assert.strictEqual(0, +res[1]);
|
||||||
}],
|
}],
|
||||||
["set", "foo2", helper.isError()],
|
['set', 'foo2', helper.isError()],
|
||||||
["incr", "batchfoo"],
|
['incr', 'batchfoo'],
|
||||||
["incr", "batchbar"]
|
['incr', 'batchbar']
|
||||||
]).exec(function (err, replies) {
|
]).exec(function (err, replies) {
|
||||||
assert.strictEqual(2, replies[0].length);
|
assert.strictEqual(2, replies[0].length);
|
||||||
assert.strictEqual(null, replies[0][0]);
|
assert.strictEqual(null, replies[0][0]);
|
||||||
assert.strictEqual(null, replies[0][1]);
|
assert.strictEqual(null, replies[0][1]);
|
||||||
assert.strictEqual('SET', replies[1].command);
|
assert.strictEqual('SET', replies[1].command);
|
||||||
assert.strictEqual("1", replies[2].toString());
|
assert.strictEqual('1', replies[2].toString());
|
||||||
assert.strictEqual("1", replies[3].toString());
|
assert.strictEqual('1', replies[3].toString());
|
||||||
return done();
|
return done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles multiple operations being applied to a set', function (done) {
|
it('handles multiple operations being applied to a set', function (done) {
|
||||||
client.sadd("some set", "mem 1");
|
client.sadd('some set', 'mem 1');
|
||||||
client.sadd(["some set", "mem 2"]);
|
client.sadd(['some set', 'mem 2']);
|
||||||
client.sadd("some set", "mem 3");
|
client.sadd('some set', 'mem 3');
|
||||||
client.sadd("some set", "mem 4");
|
client.sadd('some set', 'mem 4');
|
||||||
|
|
||||||
// make sure empty mb reply works
|
// make sure empty mb reply works
|
||||||
client.del("some missing set");
|
client.del('some missing set');
|
||||||
client.smembers("some missing set", function (err, reply) {
|
client.smembers('some missing set', function (err, reply) {
|
||||||
// make sure empty mb reply works
|
// make sure empty mb reply works
|
||||||
assert.strictEqual(0, reply.length);
|
assert.strictEqual(0, reply.length);
|
||||||
});
|
});
|
||||||
|
|
||||||
// test nested batch-bulk replies with empty mb elements.
|
// test nested batch-bulk replies with empty mb elements.
|
||||||
client.BATCH([
|
client.BATCH([
|
||||||
["smembers", ["some set"]],
|
['smembers', ['some set']],
|
||||||
["del", "some set"],
|
['del', 'some set'],
|
||||||
["smembers", "some set", undefined] // The explicit undefined is handled as a callback that is undefined
|
['smembers', 'some set', undefined] // The explicit undefined is handled as a callback that is undefined
|
||||||
])
|
])
|
||||||
.scard("some set")
|
.scard('some set')
|
||||||
.exec(function (err, replies) {
|
.exec(function (err, replies) {
|
||||||
assert.strictEqual(4, replies[0].length);
|
assert.strictEqual(4, replies[0].length);
|
||||||
assert.strictEqual(0, replies[2].length);
|
assert.strictEqual(0, replies[2].length);
|
||||||
@@ -194,21 +187,21 @@ describe("The 'batch' method", function () {
|
|||||||
|
|
||||||
it('allows multiple operations to be performed using constructor with all kinds of syntax', function (done) {
|
it('allows multiple operations to be performed using constructor with all kinds of syntax', function (done) {
|
||||||
var now = Date.now();
|
var now = Date.now();
|
||||||
var arr = ["batchhmset", "batchbar", "batchbaz"];
|
var arr = ['batchhmset', 'batchbar', 'batchbaz'];
|
||||||
var arr2 = ['some manner of key', 'otherTypes'];
|
var arr2 = ['some manner of key', 'otherTypes'];
|
||||||
var arr3 = [5768, "batchbarx", "batchfoox"];
|
var arr3 = [5768, 'batchbarx', 'batchfoox'];
|
||||||
var arr4 = ["mset", [578, "batchbar"], helper.isString('OK')];
|
var arr4 = ['mset', [578, 'batchbar'], helper.isString('OK')];
|
||||||
client.batch([
|
client.batch([
|
||||||
arr4,
|
arr4,
|
||||||
[["mset", "batchfoo2", "batchbar2", "batchfoo3", "batchbar3"], helper.isString('OK')],
|
[['mset', 'batchfoo2', 'batchbar2', 'batchfoo3', 'batchbar3'], helper.isString('OK')],
|
||||||
["hmset", arr],
|
['hmset', arr],
|
||||||
[["hmset", "batchhmset2", "batchbar2", "batchfoo3", "batchbar3", "test"], helper.isString('OK')],
|
[['hmset', 'batchhmset2', 'batchbar2', 'batchfoo3', 'batchbar3', 'test'], helper.isString('OK')],
|
||||||
["hmset", ["batchhmset", "batchbar", "batchfoo"], helper.isString('OK')],
|
['hmset', ['batchhmset', 'batchbar', 'batchfoo'], helper.isString('OK')],
|
||||||
["hmset", arr3, helper.isString('OK')],
|
['hmset', arr3, helper.isString('OK')],
|
||||||
['hmset', now, {123456789: "abcdefghij", "some manner of key": "a type of value", "otherTypes": 555}],
|
['hmset', now, {123456789: 'abcdefghij', 'some manner of key': 'a type of value', 'otherTypes': 555}],
|
||||||
['hmset', 'key2', {"0123456789": "abcdefghij", "some manner of key": "a type of value", "otherTypes": 999}, helper.isString('OK')],
|
['hmset', 'key2', {'0123456789': 'abcdefghij', 'some manner of key': 'a type of value', 'otherTypes': 999}, helper.isString('OK')],
|
||||||
["HMSET", "batchhmset", ["batchbar", "batchbaz"]],
|
['HMSET', 'batchhmset', ['batchbar', 'batchbaz']],
|
||||||
["hmset", "batchhmset", ["batchbar", "batchbaz"], helper.isString('OK')],
|
['hmset', 'batchhmset', ['batchbar', 'batchbaz'], helper.isString('OK')],
|
||||||
])
|
])
|
||||||
.hmget(now, 123456789, 'otherTypes')
|
.hmget(now, 123456789, 'otherTypes')
|
||||||
.hmget('key2', arr2, function noop () {})
|
.hmget('key2', arr2, function noop () {})
|
||||||
@@ -310,8 +303,8 @@ describe("The 'batch' method", function () {
|
|||||||
it('allows an array to be provided indicating multiple operations to perform', function (done) {
|
it('allows an array to be provided indicating multiple operations to perform', function (done) {
|
||||||
// test nested batch-bulk replies with nulls.
|
// test nested batch-bulk replies with nulls.
|
||||||
client.batch([
|
client.batch([
|
||||||
["mget", ["batchfoo", "some", "random value", "keys"]],
|
['mget', ['batchfoo', 'some', 'random value', 'keys']],
|
||||||
["incr", "batchfoo"]
|
['incr', 'batchfoo']
|
||||||
])
|
])
|
||||||
.exec(function (err, replies) {
|
.exec(function (err, replies) {
|
||||||
assert.strictEqual(replies.length, 2);
|
assert.strictEqual(replies.length, 2);
|
||||||
@@ -322,19 +315,19 @@ describe("The 'batch' method", function () {
|
|||||||
|
|
||||||
it('allows multiple operations to be performed on a hash', function (done) {
|
it('allows multiple operations to be performed on a hash', function (done) {
|
||||||
client.batch()
|
client.batch()
|
||||||
.hmset("batchhash", "a", "foo", "b", 1)
|
.hmset('batchhash', 'a', 'foo', 'b', 1)
|
||||||
.hmset("batchhash", {
|
.hmset('batchhash', {
|
||||||
extra: "fancy",
|
extra: 'fancy',
|
||||||
things: "here"
|
things: 'here'
|
||||||
})
|
})
|
||||||
.hgetall("batchhash")
|
.hgetall('batchhash')
|
||||||
.exec(done);
|
.exec(done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should work without any callback or arguments", function (done) {
|
it('should work without any callback or arguments', function (done) {
|
||||||
var batch = client.batch();
|
var batch = client.batch();
|
||||||
batch.set("baz", "binary");
|
batch.set('baz', 'binary');
|
||||||
batch.set("foo", "bar");
|
batch.set('foo', 'bar');
|
||||||
batch.ping();
|
batch.ping();
|
||||||
batch.exec();
|
batch.exec();
|
||||||
|
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require("assert");
|
var assert = require('assert');
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var helper = require("../helper");
|
var helper = require('../helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
var intercept = require('intercept-stdout');
|
var intercept = require('intercept-stdout');
|
||||||
|
|
||||||
@@ -10,13 +10,13 @@ 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 client;
|
||||||
var bclient;
|
var bclient;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.flushdb(done);
|
client.flushdb(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -29,40 +29,40 @@ describe("The 'blpop' method", function () {
|
|||||||
text += data;
|
text += data;
|
||||||
return '';
|
return '';
|
||||||
});
|
});
|
||||||
client.rpush("blocking list", "initial value", helper.isNumber(1));
|
client.rpush('blocking list', 'initial value', helper.isNumber(1));
|
||||||
unhookIntercept();
|
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));
|
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;
|
redis.debug_mode = false;
|
||||||
bclient.blpop("blocking list", 0, function (err, value) {
|
bclient.blpop('blocking list', 0, function (err, value) {
|
||||||
assert.strictEqual(value[0], "blocking list");
|
assert.strictEqual(value[0], 'blocking list');
|
||||||
assert.strictEqual(value[1], "initial value");
|
assert.strictEqual(value[1], 'initial value');
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('pops value immediately if list contains values using array notation', function (done) {
|
it('pops value immediately if list contains values using array notation', function (done) {
|
||||||
bclient = redis.createClient.apply(null, args);
|
bclient = redis.createClient.apply(null, args);
|
||||||
client.rpush(["blocking list", "initial value"], helper.isNumber(1));
|
client.rpush(['blocking list', 'initial value'], helper.isNumber(1));
|
||||||
bclient.blpop(["blocking list", 0], function (err, value) {
|
bclient.blpop(['blocking list', 0], function (err, value) {
|
||||||
assert.strictEqual(value[0], "blocking list");
|
assert.strictEqual(value[0], 'blocking list');
|
||||||
assert.strictEqual(value[1], "initial value");
|
assert.strictEqual(value[1], 'initial value');
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('waits for value if list is not yet populated', function (done) {
|
it('waits for value if list is not yet populated', function (done) {
|
||||||
bclient = redis.createClient.apply(null, args);
|
bclient = redis.createClient.apply(null, args);
|
||||||
bclient.blpop("blocking list 2", 5, function (err, value) {
|
bclient.blpop('blocking list 2', 5, function (err, value) {
|
||||||
assert.strictEqual(value[0], "blocking list 2");
|
assert.strictEqual(value[0], 'blocking list 2');
|
||||||
assert.strictEqual(value[1], "initial value");
|
assert.strictEqual(value[1], 'initial value');
|
||||||
return done(err);
|
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) {
|
it('times out after specified time', function (done) {
|
||||||
bclient = redis.createClient.apply(null, args);
|
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);
|
assert.strictEqual(res, null);
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require("assert");
|
var assert = require('assert');
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var helper = require("../helper");
|
var helper = require('../helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
describe("The 'client' method", function () {
|
describe("The 'client' method", function () {
|
||||||
@@ -10,12 +10,12 @@ describe("The 'client' method", function () {
|
|||||||
helper.allTests(function (parser, ip, args) {
|
helper.allTests(function (parser, ip, args) {
|
||||||
var pattern = /addr=/;
|
var pattern = /addr=/;
|
||||||
|
|
||||||
describe("using " + parser + " and " + ip, function () {
|
describe('using ' + parser + ' and ' + ip, function () {
|
||||||
var client;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.flushdb(done);
|
client.flushdb(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -26,18 +26,18 @@ describe("The 'client' method", function () {
|
|||||||
|
|
||||||
describe('list', function () {
|
describe('list', function () {
|
||||||
it('lists connected clients', function (done) {
|
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) {
|
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());
|
assert(pattern.test(results[0]), "expected string '" + results + "' to match " + pattern.toString());
|
||||||
return done();
|
return done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("lists connected clients when invoked with array syntax on client", function (done) {
|
it('lists connected clients when invoked with array syntax on client', 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());
|
assert(pattern.test(results[0]), "expected string '" + results + "' to match " + pattern.toString());
|
||||||
return done();
|
return done();
|
||||||
});
|
});
|
||||||
@@ -58,7 +58,7 @@ describe("The 'client' method", function () {
|
|||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client2 = redis.createClient.apply(redis.createClient, args);
|
client2 = redis.createClient.apply(redis.createClient, args);
|
||||||
client2.once("ready", function () {
|
client2.once('ready', function () {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -72,14 +72,14 @@ describe("The 'client' method", function () {
|
|||||||
// per chunk. So the execution order is only garanteed on each client
|
// per chunk. So the execution order is only garanteed on each client
|
||||||
var end = helper.callFuncAfter(done, 2);
|
var end = helper.callFuncAfter(done, 2);
|
||||||
|
|
||||||
client.client("setname", "RUTH", helper.isString('OK'));
|
client.client('setname', 'RUTH', helper.isString('OK'));
|
||||||
client2.client("setname", "RENEE", helper.isString('OK'));
|
client2.client('setname', 'RENEE', helper.isString('OK'));
|
||||||
client2.client("setname", "MARTIN", helper.isString('OK'));
|
client2.client('setname', 'MARTIN', helper.isString('OK'));
|
||||||
client2.client("getname", function(err, res) {
|
client2.client('getname', function (err, res) {
|
||||||
assert.equal(res, 'MARTIN');
|
assert.equal(res, 'MARTIN');
|
||||||
end();
|
end();
|
||||||
});
|
});
|
||||||
client.client("getname", function(err, res) {
|
client.client('getname', function (err, res) {
|
||||||
assert.equal(res, 'RUTH');
|
assert.equal(res, 'RUTH');
|
||||||
end();
|
end();
|
||||||
});
|
});
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var helper = require('../helper');
|
var helper = require('../helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
var uuid = require('uuid');
|
var uuid = require('uuid');
|
||||||
@@ -10,7 +10,7 @@ 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;
|
var key, value;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
@@ -18,18 +18,18 @@ describe("The 'dbsize' method", function () {
|
|||||||
value = uuid.v4();
|
value = uuid.v4();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when not connected", function () {
|
describe('when not connected', function () {
|
||||||
var client;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.quit();
|
client.quit();
|
||||||
});
|
});
|
||||||
client.on('end', done);
|
client.on('end', done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("reports an error", function (done) {
|
it('reports an error', function (done) {
|
||||||
client.dbsize([], function (err, res) {
|
client.dbsize([], function (err, res) {
|
||||||
assert(err.message.match(/The connection has already been closed/));
|
assert(err.message.match(/The connection has already been closed/));
|
||||||
done();
|
done();
|
||||||
@@ -37,14 +37,14 @@ describe("The 'dbsize' method", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when connected", function () {
|
describe('when connected', function () {
|
||||||
var client;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.flushdb(function (err, res) {
|
client.flushdb(function (err, res) {
|
||||||
helper.isString("OK")(err, res);
|
helper.isString('OK')(err, res);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -54,22 +54,22 @@ describe("The 'dbsize' method", function () {
|
|||||||
client.end(true);
|
client.end(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns a zero db size", function (done) {
|
it('returns a zero db size', function (done) {
|
||||||
client.DBSIZE([], function (err, res) {
|
client.DBSIZE([], function (err, res) {
|
||||||
helper.isNotError()(err, res);
|
helper.isNotError()(err, res);
|
||||||
helper.isType.number()(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();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when more data is added to Redis", function () {
|
describe('when more data is added to Redis', function () {
|
||||||
var oldSize;
|
var oldSize;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client.dbsize(function (err, res) {
|
client.dbsize(function (err, res) {
|
||||||
helper.isType.number()(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;
|
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) {
|
client.dbsize([], function (err, res) {
|
||||||
helper.isNotError()(err, res);
|
helper.isNotError()(err, res);
|
||||||
helper.isType.positiveNumber()(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();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -1,19 +1,19 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var helper = require("../helper");
|
var helper = require('../helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
describe("The 'del' method", function () {
|
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;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.flushdb(done);
|
client.flushdb(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -1,22 +1,22 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require("assert");
|
var assert = require('assert');
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var crypto = require("crypto");
|
var crypto = require('crypto');
|
||||||
var helper = require("../helper");
|
var helper = require('../helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
describe("The 'eval' method", function () {
|
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 client;
|
||||||
var source = "return redis.call('set', 'sha', 'test')";
|
var source = "return redis.call('set', 'sha', 'test')";
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.flushdb(done);
|
client.flushdb(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -26,7 +26,7 @@ describe("The 'eval' method", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('converts a float to an integer when evaluated', function (done) {
|
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) {
|
it('returns a string', function (done) {
|
||||||
@@ -34,11 +34,11 @@ describe("The 'eval' method", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('converts boolean true to integer 1', function (done) {
|
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) {
|
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) {
|
it('converts lua status code to string representation', function (done) {
|
||||||
@@ -59,7 +59,7 @@ describe("The 'eval' method", function () {
|
|||||||
assert.strictEqual(1, res[0]);
|
assert.strictEqual(1, res[0]);
|
||||||
assert.strictEqual(2, res[1]);
|
assert.strictEqual(2, res[1]);
|
||||||
assert.strictEqual(3, res[2]);
|
assert.strictEqual(3, res[2]);
|
||||||
assert.strictEqual("ciao", res[3]);
|
assert.strictEqual('ciao', res[3]);
|
||||||
assert.strictEqual(2, res[4].length);
|
assert.strictEqual(2, res[4].length);
|
||||||
assert.strictEqual(1, res[4][0]);
|
assert.strictEqual(1, res[4][0]);
|
||||||
assert.strictEqual(2, res[4][1]);
|
assert.strictEqual(2, res[4][1]);
|
||||||
@@ -68,23 +68,23 @@ describe("The 'eval' method", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('populates keys and argv correctly', function (done) {
|
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(4, res.length);
|
||||||
assert.strictEqual("a", res[0]);
|
assert.strictEqual('a', res[0]);
|
||||||
assert.strictEqual("b", res[1]);
|
assert.strictEqual('b', res[1]);
|
||||||
assert.strictEqual("c", res[2]);
|
assert.strictEqual('c', res[2]);
|
||||||
assert.strictEqual("d", res[3]);
|
assert.strictEqual('d', res[3]);
|
||||||
return done();
|
return done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('allows arguments to be provided in array rather than as multiple parameters', function (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(4, res.length);
|
||||||
assert.strictEqual("a", res[0]);
|
assert.strictEqual('a', res[0]);
|
||||||
assert.strictEqual("b", res[1]);
|
assert.strictEqual('b', res[1]);
|
||||||
assert.strictEqual("c", res[2]);
|
assert.strictEqual('c', res[2]);
|
||||||
assert.strictEqual("d", res[3]);
|
assert.strictEqual('d', res[3]);
|
||||||
return done();
|
return 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) {
|
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);
|
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(2, res.length);
|
||||||
assert.strictEqual("number", res[0]);
|
assert.strictEqual('number', res[0]);
|
||||||
assert.strictEqual(1, res[1]);
|
assert.strictEqual(1, res[1]);
|
||||||
return done(err);
|
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) {
|
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) {
|
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(2, res.length);
|
||||||
assert.strictEqual("string", res[0]);
|
assert.strictEqual('string', res[0]);
|
||||||
assert.strictEqual("bulk reply value", res[1]);
|
assert.strictEqual('bulk reply value', res[1]);
|
||||||
return done(err);
|
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) {
|
it('allows a multi mulk operation to be performed, with the appropriate type conversion', function (done) {
|
||||||
client.multi()
|
client.multi()
|
||||||
.del("mylist")
|
.del('mylist')
|
||||||
.rpush("mylist", "a")
|
.rpush('mylist', 'a')
|
||||||
.rpush("mylist", "b")
|
.rpush('mylist', 'b')
|
||||||
.rpush("mylist", "c")
|
.rpush('mylist', 'c')
|
||||||
.exec(function (err, replies) {
|
.exec(function (err, replies) {
|
||||||
if (err) return done(err);
|
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) {
|
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(5, res.length);
|
||||||
assert.strictEqual("table", res[0]);
|
assert.strictEqual('table', res[0]);
|
||||||
assert.strictEqual("a", res[1]);
|
assert.strictEqual('a', res[1]);
|
||||||
assert.strictEqual("b", res[2]);
|
assert.strictEqual('b', res[2]);
|
||||||
assert.strictEqual("c", res[3]);
|
assert.strictEqual('c', res[3]);
|
||||||
assert.strictEqual(3, res[4]);
|
assert.strictEqual(3, res[4]);
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
@@ -175,31 +175,31 @@ describe("The 'eval' method", function () {
|
|||||||
it('returns an appropriate representation of Lua status reply', function (done) {
|
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) {
|
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(2, res.length);
|
||||||
assert.strictEqual("table", res[0]);
|
assert.strictEqual('table', res[0]);
|
||||||
assert.strictEqual("OK", res[1]);
|
assert.strictEqual('OK', res[1]);
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns an appropriate representation of a Lua error reply', function (done) {
|
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);
|
if (err) return done(err);
|
||||||
client.eval("local foo = redis.pcall('incr','error reply key'); return {type(foo),foo['err']}", 0, function (err, res) {
|
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(2, res.length);
|
||||||
assert.strictEqual("table", res[0]);
|
assert.strictEqual('table', res[0]);
|
||||||
assert.strictEqual("ERR value is not an integer or out of range", res[1]);
|
assert.strictEqual('ERR value is not an integer or out of range', res[1]);
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns an appropriate representation of a Lua nil reply', function (done) {
|
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);
|
if (err) return done(err);
|
||||||
client.eval("local foo = redis.call('get','nil reply key'); return {type(foo),foo == false}", 0, function (err, res) {
|
client.eval("local foo = redis.call('get','nil reply key'); return {type(foo),foo == false}", 0, function (err, res) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(2, res.length);
|
assert.strictEqual(2, res.length);
|
||||||
assert.strictEqual("boolean", res[0]);
|
assert.strictEqual('boolean', res[0]);
|
||||||
assert.strictEqual(1, res[1]);
|
assert.strictEqual(1, res[1]);
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
|
@@ -1,19 +1,19 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var helper = require("../helper");
|
var helper = require('../helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
describe("The 'exists' method", function () {
|
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;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.flushdb(done);
|
client.flushdb(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -1,36 +1,36 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var helper = require("../helper");
|
var helper = require('../helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
describe("The 'expire' method", function () {
|
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;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.flushdb(done);
|
client.flushdb(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('expires key after timeout', function (done) {
|
it('expires key after timeout', function (done) {
|
||||||
client.set(['expiry key', 'bar'], helper.isString("OK"));
|
client.set(['expiry key', 'bar'], helper.isString('OK'));
|
||||||
client.EXPIRE("expiry key", "1", helper.isNumber(1));
|
client.EXPIRE('expiry key', '1', helper.isNumber(1));
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
client.exists(["expiry key"], helper.isNumber(0, done));
|
client.exists(['expiry key'], helper.isNumber(0, done));
|
||||||
}, 1100);
|
}, 1100);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('expires key after timeout with array syntax', function (done) {
|
it('expires key after timeout with array syntax', function (done) {
|
||||||
client.set(['expiry key', 'bar'], helper.isString("OK"));
|
client.set(['expiry key', 'bar'], helper.isString('OK'));
|
||||||
client.EXPIRE(["expiry key", "1"], helper.isNumber(1));
|
client.EXPIRE(['expiry key', '1'], helper.isNumber(1));
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
client.exists(["expiry key"], helper.isNumber(0, done));
|
client.exists(['expiry key'], helper.isNumber(0, done));
|
||||||
}, 1100);
|
}, 1100);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var helper = require('../helper');
|
var helper = require('../helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
var uuid = require('uuid');
|
var uuid = require('uuid');
|
||||||
@@ -10,7 +10,7 @@ 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;
|
var key, key2;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
@@ -18,18 +18,18 @@ describe("The 'flushdb' method", function () {
|
|||||||
key2 = uuid.v4();
|
key2 = uuid.v4();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when not connected", function () {
|
describe('when not connected', function () {
|
||||||
var client;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.quit();
|
client.quit();
|
||||||
});
|
});
|
||||||
client.on('end', done);
|
client.on('end', done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("reports an error", function (done) {
|
it('reports an error', function (done) {
|
||||||
client.flushdb(function (err, res) {
|
client.flushdb(function (err, res) {
|
||||||
assert(err.message.match(/The connection has already been closed/));
|
assert(err.message.match(/The connection has already been closed/));
|
||||||
done();
|
done();
|
||||||
@@ -37,12 +37,12 @@ describe("The 'flushdb' method", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when connected", function () {
|
describe('when connected', function () {
|
||||||
var client;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -51,7 +51,7 @@ describe("The 'flushdb' method", function () {
|
|||||||
client.end(true);
|
client.end(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when there is data in Redis", function () {
|
describe('when there is data in Redis', function () {
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client.mset(key, uuid.v4(), key2, uuid.v4(), helper.isNotError());
|
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) {
|
it('deletes all the keys', function (done) {
|
||||||
client.flushdb(function (err, res) {
|
client.flushdb(function (err, res) {
|
||||||
assert.equal(res, 'OK');
|
assert.equal(res, 'OK');
|
||||||
client.mget(key, key2, function (err, res) {
|
client.mget(key, key2, function (err, res) {
|
||||||
assert.strictEqual(null, err, "Unexpected error returned");
|
assert.strictEqual(null, err, 'Unexpected error returned');
|
||||||
assert.strictEqual(true, Array.isArray(res), "Results object should be an array.");
|
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(2, res.length, 'Results array should have length 2.');
|
||||||
assert.strictEqual(null, res[0], "Redis key should have been flushed.");
|
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, res[1], 'Redis key should have been flushed.');
|
||||||
done(err);
|
done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("results in a db size of zero", function (done) {
|
it('results in a db size of zero', function (done) {
|
||||||
client.flushdb(function (err, res) {
|
client.flushdb(function (err, res) {
|
||||||
client.dbsize([], function (err, res) {
|
client.dbsize([], function (err, res) {
|
||||||
helper.isNotError()(err, res);
|
helper.isNotError()(err, res);
|
||||||
helper.isType.number()(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();
|
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();
|
client.flushdb();
|
||||||
setTimeout(function (err, res) {
|
setTimeout(function (err, res) {
|
||||||
client.dbsize([], function (err, res) {
|
client.dbsize([], function (err, res) {
|
||||||
helper.isNotError()(err, res);
|
helper.isNotError()(err, res);
|
||||||
helper.isType.number()(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();
|
done();
|
||||||
});
|
});
|
||||||
}, 25);
|
}, 25);
|
||||||
|
@@ -1,26 +1,26 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var helper = require("../helper");
|
var helper = require('../helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
describe("The 'geoadd' method", function () {
|
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;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.flushdb(done);
|
client.flushdb(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns 1 if the key exists', function (done) {
|
it('returns 1 if the key exists', function (done) {
|
||||||
helper.serverVersionAtLeast.call(this, client, [3, 2, 0]);
|
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);
|
console.log(err, res);
|
||||||
// geoadd is still in the unstable branch. As soon as it reaches the stable one, activate this test
|
// geoadd is still in the unstable branch. As soon as it reaches the stable one, activate this test
|
||||||
done();
|
done();
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var helper = require('../helper');
|
var helper = require('../helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
var uuid = require('uuid');
|
var uuid = require('uuid');
|
||||||
@@ -10,7 +10,7 @@ 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;
|
var key, value;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
@@ -18,37 +18,37 @@ describe("The 'get' method", function () {
|
|||||||
value = uuid.v4();
|
value = uuid.v4();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when not connected", function () {
|
describe('when not connected', function () {
|
||||||
var client;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.quit();
|
client.quit();
|
||||||
});
|
});
|
||||||
client.on('end', done);
|
client.on('end', done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("reports an error", function (done) {
|
it('reports an error', function (done) {
|
||||||
client.get(key, function (err, res) {
|
client.get(key, function (err, res) {
|
||||||
assert(err.message.match(/The connection has already been closed/));
|
assert(err.message.match(/The connection has already been closed/));
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("reports an error promisified", function () {
|
it('reports an error promisified', function () {
|
||||||
return client.getAsync(key).then(assert, function (err) {
|
return client.getAsync(key).then(assert, function (err) {
|
||||||
assert(err.message.match(/The connection has already been closed/));
|
assert(err.message.match(/The connection has already been closed/));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when connected", function () {
|
describe('when connected', function () {
|
||||||
var client;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -57,7 +57,7 @@ describe("The 'get' method", function () {
|
|||||||
client.end(true);
|
client.end(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when the key exists in Redis", function () {
|
describe('when the key exists in Redis', function () {
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client.set(key, value, function (err, res) {
|
client.set(key, value, function (err, res) {
|
||||||
helper.isNotError()(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) {
|
client.GET(key, function (err, res) {
|
||||||
helper.isString(value)(err, res);
|
helper.isString(value)(err, res);
|
||||||
done(err);
|
done(err);
|
||||||
@@ -81,8 +81,8 @@ describe("The 'get' method", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when the key does not exist in Redis", function () {
|
describe('when the key does not exist in Redis', function () {
|
||||||
it("gets a null value", function (done) {
|
it('gets a null value', function (done) {
|
||||||
client.get(key, function (err, res) {
|
client.get(key, function (err, res) {
|
||||||
helper.isNull()(err, res);
|
helper.isNull()(err, res);
|
||||||
done(err);
|
done(err);
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var helper = require('../helper');
|
var helper = require('../helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
var uuid = require('uuid');
|
var uuid = require('uuid');
|
||||||
@@ -10,7 +10,7 @@ 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;
|
var key, value, value2;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
@@ -19,18 +19,18 @@ describe("The 'getset' method", function () {
|
|||||||
value2 = uuid.v4();
|
value2 = uuid.v4();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when not connected", function () {
|
describe('when not connected', function () {
|
||||||
var client;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.quit();
|
client.quit();
|
||||||
});
|
});
|
||||||
client.on('end', done);
|
client.on('end', done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("reports an error", function (done) {
|
it('reports an error', function (done) {
|
||||||
client.get(key, function (err, res) {
|
client.get(key, function (err, res) {
|
||||||
assert(err.message.match(/The connection has already been closed/));
|
assert(err.message.match(/The connection has already been closed/));
|
||||||
done();
|
done();
|
||||||
@@ -38,12 +38,12 @@ describe("The 'getset' method", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when connected", function () {
|
describe('when connected', function () {
|
||||||
var client;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -52,7 +52,7 @@ describe("The 'getset' method", function () {
|
|||||||
client.end(true);
|
client.end(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when the key exists in Redis", function () {
|
describe('when the key exists in Redis', function () {
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client.set(key, value, function (err, res) {
|
client.set(key, value, function (err, res) {
|
||||||
helper.isNotError()(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) {
|
client.GETSET(key, value2, function (err, res) {
|
||||||
helper.isString(value)(err, res);
|
helper.isString(value)(err, res);
|
||||||
client.get(key, function (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) {
|
client.GETSET([key, value2], function (err, res) {
|
||||||
helper.isString(value)(err, res);
|
helper.isString(value)(err, res);
|
||||||
client.get(key, function (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) {
|
client.GETSET(key, [value2], function (err, res) {
|
||||||
helper.isString(value)(err, res);
|
helper.isString(value)(err, res);
|
||||||
client.get(key, function (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 () {
|
describe('when the key does not exist in Redis', function () {
|
||||||
it("gets a null value", function (done) {
|
it('gets a null value', function (done) {
|
||||||
client.getset(key, value, function (err, res) {
|
client.getset(key, value, function (err, res) {
|
||||||
helper.isNull()(err, res);
|
helper.isNull()(err, res);
|
||||||
done(err);
|
done(err);
|
||||||
|
@@ -1,48 +1,48 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require("assert");
|
var assert = require('assert');
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var helper = require("../helper");
|
var helper = require('../helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
describe("The 'hgetall' method", function () {
|
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;
|
var client;
|
||||||
|
|
||||||
describe('regular client', function () {
|
describe('regular client', function () {
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.flushdb(done);
|
client.flushdb(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles simple keys and values', function (done) {
|
it('handles simple keys and values', function (done) {
|
||||||
client.hmset(["hosts", "mjr", "1", "another", "23", "home", "1234"], helper.isString("OK"));
|
client.hmset(['hosts', 'mjr', '1', 'another', '23', 'home', '1234'], helper.isString('OK'));
|
||||||
client.HGETALL(["hosts"], function (err, obj) {
|
client.HGETALL(['hosts'], function (err, obj) {
|
||||||
assert.strictEqual(3, Object.keys(obj).length);
|
assert.strictEqual(3, Object.keys(obj).length);
|
||||||
assert.strictEqual("1", obj.mjr.toString());
|
assert.strictEqual('1', obj.mjr.toString());
|
||||||
assert.strictEqual("23", obj.another.toString());
|
assert.strictEqual('23', obj.another.toString());
|
||||||
assert.strictEqual("1234", obj.home.toString());
|
assert.strictEqual('1234', obj.home.toString());
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles fetching keys set using an object', function (done) {
|
it('handles fetching keys set using an object', function (done) {
|
||||||
client.HMSET("msg_test", { message: "hello" }, helper.isString("OK"));
|
client.HMSET('msg_test', { message: 'hello' }, helper.isString('OK'));
|
||||||
client.hgetall("msg_test", function (err, obj) {
|
client.hgetall('msg_test', function (err, obj) {
|
||||||
assert.strictEqual(1, Object.keys(obj).length);
|
assert.strictEqual(1, Object.keys(obj).length);
|
||||||
assert.strictEqual(obj.message, "hello");
|
assert.strictEqual(obj.message, 'hello');
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles fetching a messing key', function (done) {
|
it('handles fetching a messing key', function (done) {
|
||||||
client.hgetall("missing", function (err, obj) {
|
client.hgetall('missing', function (err, obj) {
|
||||||
assert.strictEqual(null, obj);
|
assert.strictEqual(null, obj);
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
@@ -57,18 +57,18 @@ describe("The 'hgetall' method", function () {
|
|||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.flushdb(done);
|
client.flushdb(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns binary results', function (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.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.HGETALL('bhosts', function (err, obj) {
|
||||||
assert.strictEqual(4, Object.keys(obj).length);
|
assert.strictEqual(4, Object.keys(obj).length);
|
||||||
assert.strictEqual("1", obj.mjr.toString());
|
assert.strictEqual('1', obj.mjr.toString());
|
||||||
assert.strictEqual("23", obj.another.toString());
|
assert.strictEqual('23', obj.another.toString());
|
||||||
assert.strictEqual("1234", obj.home.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([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'));
|
assert.strictEqual((new Buffer([0xCC, 0xDD, 0x00, 0xF0])).toString('binary'), obj[(new Buffer([0xAA, 0xBB, 0x00, 0xF0])).toString('binary')].toString('binary'));
|
||||||
return done(err);
|
return done(err);
|
||||||
|
@@ -1,33 +1,33 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var helper = require("../helper");
|
var helper = require('../helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
describe("The 'hincrby' method", function () {
|
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 client;
|
||||||
var hash = "test hash";
|
var hash = 'test hash';
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.flushdb(done);
|
client.flushdb(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('increments a key that has already been set', function (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.HSET(hash, field, 33);
|
||||||
client.hincrby(hash, field, 10, helper.isNumber(43, done));
|
client.hincrby(hash, field, 10, helper.isNumber(43, done));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('increments a key that has not been set', function (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));
|
client.HINCRBY(hash, field, 10, helper.isNumber(10, done));
|
||||||
});
|
});
|
||||||
|
@@ -1,27 +1,27 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var helper = require("../helper");
|
var helper = require('../helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
describe("The 'hlen' method", function () {
|
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;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.flushdb(done);
|
client.flushdb(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('reports the count of keys', function (done) {
|
it('reports the count of keys', function (done) {
|
||||||
var hash = "test hash";
|
var hash = 'test hash';
|
||||||
var field1 = new Buffer("0123456789");
|
var field1 = new Buffer('0123456789');
|
||||||
var value1 = new Buffer("abcdefghij");
|
var value1 = new Buffer('abcdefghij');
|
||||||
var field2 = new Buffer(0);
|
var field2 = new Buffer(0);
|
||||||
var value2 = new Buffer(0);
|
var value2 = new Buffer(0);
|
||||||
|
|
||||||
|
@@ -1,62 +1,62 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require("assert");
|
var assert = require('assert');
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var helper = require("../helper");
|
var helper = require('../helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
describe("The 'hmget' method", function () {
|
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 client;
|
||||||
var hash = 'test hash';
|
var hash = 'test hash';
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("error", done);
|
client.once('error', done);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.flushdb();
|
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) {
|
it('allows keys to be specified using multiple arguments', function (done) {
|
||||||
client.hmget(hash, "0123456789", "some manner of key", function (err, reply) {
|
client.hmget(hash, '0123456789', 'some manner of key', function (err, reply) {
|
||||||
assert.strictEqual("abcdefghij", reply[0].toString());
|
assert.strictEqual('abcdefghij', reply[0].toString());
|
||||||
assert.strictEqual("a type of value", reply[1].toString());
|
assert.strictEqual('a type of value', reply[1].toString());
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('allows keys to be specified by passing an array without manipulating the array', function (done) {
|
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) {
|
client.HMGET(hash, data, function (err, reply) {
|
||||||
assert.strictEqual(data.length, 2);
|
assert.strictEqual(data.length, 2);
|
||||||
assert.strictEqual("abcdefghij", reply[0].toString());
|
assert.strictEqual('abcdefghij', reply[0].toString());
|
||||||
assert.strictEqual("a type of value", reply[1].toString());
|
assert.strictEqual('a type of value', reply[1].toString());
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('allows keys to be specified by passing an array as first argument', function (done) {
|
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) {
|
client.HMGET([hash, '0123456789', 'some manner of key'], function (err, reply) {
|
||||||
assert.strictEqual("abcdefghij", reply[0].toString());
|
assert.strictEqual('abcdefghij', reply[0].toString());
|
||||||
assert.strictEqual("a type of value", reply[1].toString());
|
assert.strictEqual('a type of value', reply[1].toString());
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('allows a single key to be specified in an array', function (done) {
|
it('allows a single key to be specified in an array', function (done) {
|
||||||
client.HMGET(hash, ["0123456789"], function (err, reply) {
|
client.HMGET(hash, ['0123456789'], function (err, reply) {
|
||||||
assert.strictEqual("abcdefghij", reply[0].toString());
|
assert.strictEqual('abcdefghij', reply[0].toString());
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('allows keys to be specified that have not yet been set', function (done) {
|
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[0]);
|
||||||
assert.strictEqual(null, reply[1]);
|
assert.strictEqual(null, reply[1]);
|
||||||
return done(err);
|
return done(err);
|
||||||
|
@@ -1,27 +1,27 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require("assert");
|
var assert = require('assert');
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var helper = require("../helper");
|
var helper = require('../helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
describe("The 'hmset' method", function () {
|
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 client;
|
||||||
var hash = 'test hash';
|
var hash = 'test hash';
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.flushdb(done);
|
client.flushdb(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles redis-style syntax', function (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) {
|
client.HGETALL(hash, function (err, obj) {
|
||||||
assert.equal(obj['0123456789'], 'abcdefghij');
|
assert.equal(obj['0123456789'], 'abcdefghij');
|
||||||
assert.equal(obj['some manner of key'], 'a type of value');
|
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) {
|
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) {
|
client.HGETALL(hash, function (err, obj) {
|
||||||
assert.equal(obj['0123456789'], 'abcdefghij');
|
assert.equal(obj['0123456789'], 'abcdefghij');
|
||||||
assert.equal(obj['some manner of key'], 'a type of value');
|
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) {
|
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) {
|
client.HGETALL(231232, function (err, obj) {
|
||||||
assert.equal(obj['0123456789'], 'abcdefghij');
|
assert.equal(obj['0123456789'], 'abcdefghij');
|
||||||
assert.equal(obj['some manner of key'], 'a type of value');
|
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) {
|
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) {
|
client.HGETALL(hash, function (err, obj) {
|
||||||
assert.equal(obj['0123456789'], 'abcdefghij');
|
assert.equal(obj['0123456789'], 'abcdefghij');
|
||||||
assert.equal(obj['some manner of key'], 'a type of value');
|
assert.equal(obj['some manner of key'], 'a type of value');
|
||||||
|
@@ -1,39 +1,39 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require("assert");
|
var assert = require('assert');
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var helper = require("../helper");
|
var helper = require('../helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
describe("The 'hset' method", function () {
|
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 client;
|
||||||
var hash = 'test hash';
|
var hash = 'test hash';
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.flushdb(done);
|
client.flushdb(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('allows a value to be set in a hash', function (done) {
|
it('allows a value to be set in a hash', function (done) {
|
||||||
var field = new Buffer("0123456789");
|
var field = new Buffer('0123456789');
|
||||||
var value = new Buffer("abcdefghij");
|
var value = new Buffer('abcdefghij');
|
||||||
|
|
||||||
client.hset(hash, field, value, helper.isNumber(1));
|
client.hset(hash, field, value, helper.isNumber(1));
|
||||||
client.HGET(hash, field, helper.isString(value.toString(), done));
|
client.HGET(hash, field, helper.isString(value.toString(), done));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles an empty value', function (done) {
|
it('handles an empty value', function (done) {
|
||||||
var field = new Buffer("0123456789");
|
var field = new Buffer('0123456789');
|
||||||
var value = new Buffer(0);
|
var value = new Buffer(0);
|
||||||
|
|
||||||
client.HSET(hash, field, value, helper.isNumber(1));
|
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) {
|
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) {
|
it('warns if someone passed a array either as field or as value', function (done) {
|
||||||
var hash = "test hash";
|
var hash = 'test hash';
|
||||||
var field = "array";
|
var field = 'array';
|
||||||
// This would be converted to "array contents" but if you use more than one entry,
|
// 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
|
// 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) {
|
client.on('warning', function (msg) {
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
msg,
|
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) {
|
it('does not error when a buffer and date are set as values on the same hash', function (done) {
|
||||||
var hash = "test hash";
|
var hash = 'test hash';
|
||||||
var field1 = "buffer";
|
var field1 = 'buffer';
|
||||||
var value1 = new Buffer("abcdefghij");
|
var value1 = new Buffer('abcdefghij');
|
||||||
var field2 = "date";
|
var field2 = 'date';
|
||||||
var value2 = new 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) {
|
it('does not error when a buffer and date are set as fields on the same hash', function (done) {
|
||||||
var hash = "test hash";
|
var hash = 'test hash';
|
||||||
var value1 = "buffer";
|
var value1 = 'buffer';
|
||||||
var field1 = new Buffer("abcdefghij");
|
var field1 = new Buffer('abcdefghij');
|
||||||
var value2 = "date";
|
var value2 = 'date';
|
||||||
var field2 = new 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 () {
|
afterEach(function () {
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var helper = require('../helper');
|
var helper = require('../helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
@@ -9,16 +9,16 @@ describe("The 'incr' 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 = "sequence";
|
var key = 'sequence';
|
||||||
|
|
||||||
describe("when not connected", function () {
|
describe('when not connected', function () {
|
||||||
var client;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.set(key, "9007199254740992", function (err, res) {
|
client.set(key, '9007199254740992', function (err, res) {
|
||||||
helper.isNotError()(err, res);
|
helper.isNotError()(err, res);
|
||||||
client.quit();
|
client.quit();
|
||||||
});
|
});
|
||||||
@@ -30,7 +30,7 @@ describe("The 'incr' method", function () {
|
|||||||
client.end(true);
|
client.end(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("reports an error", function (done) {
|
it('reports an error', function (done) {
|
||||||
client.incr(function (err, res) {
|
client.incr(function (err, res) {
|
||||||
assert(err.message.match(/The connection has already been closed/));
|
assert(err.message.match(/The connection has already been closed/));
|
||||||
done();
|
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;
|
var client;
|
||||||
|
|
||||||
before(function (done) {
|
before(function (done) {
|
||||||
@@ -51,9 +51,9 @@ describe("The 'incr' method", function () {
|
|||||||
9007199254740997 -> 9007199254740996
|
9007199254740997 -> 9007199254740996
|
||||||
*/
|
*/
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("error", done);
|
client.once('error', done);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.set(key, "9007199254740992", function (err, res) {
|
client.set(key, '9007199254740992', function (err, res) {
|
||||||
helper.isNotError()(err, res);
|
helper.isNotError()(err, res);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@@ -64,41 +64,41 @@ describe("The 'incr' method", function () {
|
|||||||
client.end(true);
|
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) {
|
client.INCR(key, function (err, res) {
|
||||||
helper.isString("9007199254740993")(err, res);
|
helper.isString('9007199254740993')(err, res);
|
||||||
done(err);
|
done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("and we call it again", function () {
|
describe('and we call it again', function () {
|
||||||
it("changes the last digit from 3 to 4", function (done) {
|
it('changes the last digit from 3 to 4', function (done) {
|
||||||
client.incr(key, function (err, res) {
|
client.incr(key, function (err, res) {
|
||||||
helper.isString("9007199254740994")(err, res);
|
helper.isString('9007199254740994')(err, res);
|
||||||
done(err);
|
done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("and again", function () {
|
describe('and again', function () {
|
||||||
it("changes the last digit from 4 to 5", function (done) {
|
it('changes the last digit from 4 to 5', function (done) {
|
||||||
client.incr(key, function (err, res) {
|
client.incr(key, function (err, res) {
|
||||||
helper.isString("9007199254740995")(err, res);
|
helper.isString('9007199254740995')(err, res);
|
||||||
done(err);
|
done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("and again", function () {
|
describe('and again', function () {
|
||||||
it("changes the last digit from 5 to 6", function (done) {
|
it('changes the last digit from 5 to 6', function (done) {
|
||||||
client.incr(key, function (err, res) {
|
client.incr(key, function (err, res) {
|
||||||
helper.isString("9007199254740996")(err, res);
|
helper.isString('9007199254740996')(err, res);
|
||||||
done(err);
|
done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("and again", function () {
|
describe('and again', function () {
|
||||||
it("changes the last digit from 6 to 7", function (done) {
|
it('changes the last digit from 6 to 7', function (done) {
|
||||||
client.incr(key, function (err, res) {
|
client.incr(key, function (err, res) {
|
||||||
helper.isString("9007199254740997")(err, res);
|
helper.isString('9007199254740997')(err, res);
|
||||||
done(err);
|
done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var helper = require('../helper');
|
var helper = require('../helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
@@ -9,12 +9,12 @@ 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;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.flushall(done);
|
client.flushall(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -23,7 +23,7 @@ describe("The 'info' method", function () {
|
|||||||
client.end(true);
|
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.set('foo', 'bar');
|
||||||
client.info();
|
client.info();
|
||||||
client.select(2, function () {
|
client.select(2, function () {
|
||||||
@@ -37,7 +37,7 @@ describe("The 'info' method", function () {
|
|||||||
}, 150);
|
}, 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.set('foo', 'bar');
|
||||||
client.info('keyspace');
|
client.info('keyspace');
|
||||||
client.select(2, function () {
|
client.select(2, function () {
|
||||||
@@ -65,7 +65,7 @@ describe("The 'info' method", function () {
|
|||||||
client.info(function () {});
|
client.info(function () {});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("emit error after a failure", function (done) {
|
it('emit error after a failure', function (done) {
|
||||||
client.info();
|
client.info();
|
||||||
client.once('error', function (err) {
|
client.once('error', function (err) {
|
||||||
assert.strictEqual(err.code, 'UNCERTAIN_STATE');
|
assert.strictEqual(err.code, 'UNCERTAIN_STATE');
|
||||||
|
@@ -1,31 +1,31 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require("assert");
|
var assert = require('assert');
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var crypto = require("crypto");
|
var crypto = require('crypto');
|
||||||
var helper = require("../helper");
|
var helper = require('../helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
describe("The 'keys' method", function () {
|
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;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.flushall(done);
|
client.flushall(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns matching keys', function (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.mset(['test keys 1', 'test val 1', 'test keys 2', 'test val 2'], helper.isString('OK'));
|
||||||
client.KEYS("test keys*", function (err, results) {
|
client.KEYS('test keys*', function (err, results) {
|
||||||
assert.strictEqual(2, results.length);
|
assert.strictEqual(2, results.length);
|
||||||
assert.ok(~results.indexOf("test keys 1"));
|
assert.ok(~results.indexOf('test keys 1'));
|
||||||
assert.ok(~results.indexOf("test keys 2"));
|
assert.ok(~results.indexOf('test keys 2'));
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -35,17 +35,17 @@ describe("The 'keys' method", function () {
|
|||||||
|
|
||||||
for (var i = 0; i < 200; i++) {
|
for (var i = 0; i < 200; i++) {
|
||||||
var key_value = [
|
var key_value = [
|
||||||
"multibulk:" + crypto.randomBytes(256).toString("hex"), // use long strings as keys to ensure generation of large packet
|
'multibulk:' + crypto.randomBytes(256).toString('hex'), // use long strings as keys to ensure generation of large packet
|
||||||
"test val " + i
|
'test val ' + i
|
||||||
];
|
];
|
||||||
keys_values.push(key_value);
|
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);
|
return a.concat(b);
|
||||||
}), helper.isString("OK"));
|
}), helper.isString('OK'));
|
||||||
|
|
||||||
client.keys("multibulk:*", function(err, results) {
|
client.keys('multibulk:*', function (err, results) {
|
||||||
assert.deepEqual(keys_values.map(function (val) {
|
assert.deepEqual(keys_values.map(function (val) {
|
||||||
return val[0];
|
return val[0];
|
||||||
}).sort(), results.sort());
|
}).sort(), results.sort());
|
||||||
|
@@ -1,64 +1,64 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require("assert");
|
var assert = require('assert');
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var helper = require("../helper");
|
var helper = require('../helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
describe("The 'mget' method", function () {
|
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;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("error", done);
|
client.once('error', done);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.flushdb();
|
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) {
|
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.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.MGET('mget keys 1', 'mget keys 2', 'mget keys 3', function (err, results) {
|
||||||
assert.strictEqual(3, results.length);
|
assert.strictEqual(3, results.length);
|
||||||
assert.strictEqual("mget val 1", results[0].toString());
|
assert.strictEqual('mget val 1', results[0].toString());
|
||||||
assert.strictEqual("mget val 2", results[1].toString());
|
assert.strictEqual('mget val 2', results[1].toString());
|
||||||
assert.strictEqual("mget val 3", results[2].toString());
|
assert.strictEqual('mget val 3', results[2].toString());
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles fetching multiple keys via an array', function (done) {
|
it('handles fetching multiple keys via an array', function (done) {
|
||||||
client.mget(["mget keys 1", "mget keys 2", "mget keys 3"], function (err, results) {
|
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 1', results[0].toString());
|
||||||
assert.strictEqual("mget val 2", results[1].toString());
|
assert.strictEqual('mget val 2', results[1].toString());
|
||||||
assert.strictEqual("mget val 3", results[2].toString());
|
assert.strictEqual('mget val 3', results[2].toString());
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles fetching multiple keys, when some keys do not exist', function (done) {
|
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(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(null, results[1]);
|
||||||
assert.strictEqual("mget val 2", results[2].toString());
|
assert.strictEqual('mget val 2', results[2].toString());
|
||||||
assert.strictEqual("mget val 3", results[3].toString());
|
assert.strictEqual('mget val 3', results[3].toString());
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles fetching multiple keys, when some keys do not exist promisified', function () {
|
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(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(null, results[1]);
|
||||||
assert.strictEqual("mget val 2", results[2].toString());
|
assert.strictEqual('mget val 2', results[2].toString());
|
||||||
assert.strictEqual("mget val 3", results[3].toString());
|
assert.strictEqual('mget val 3', results[3].toString());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var helper = require('../helper');
|
var helper = require('../helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
var uuid = require('uuid');
|
var uuid = require('uuid');
|
||||||
@@ -10,7 +10,7 @@ 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;
|
var key, value, key2, value2;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
@@ -20,18 +20,18 @@ describe("The 'mset' method", function () {
|
|||||||
value2 = uuid.v4();
|
value2 = uuid.v4();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when not connected", function () {
|
describe('when not connected', function () {
|
||||||
var client;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.quit();
|
client.quit();
|
||||||
});
|
});
|
||||||
client.on('end', done);
|
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) {
|
client.mset(key, value, key2, value2, function (err, res) {
|
||||||
assert(err.message.match(/The connection has already been closed/));
|
assert(err.message.match(/The connection has already been closed/));
|
||||||
done();
|
done();
|
||||||
@@ -39,12 +39,12 @@ describe("The 'mset' method", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when connected", function () {
|
describe('when connected', function () {
|
||||||
var client;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -53,9 +53,9 @@ describe("The 'mset' method", function () {
|
|||||||
client.end(true);
|
client.end(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("and a callback is specified", function () {
|
describe('and a callback is specified', function () {
|
||||||
describe("with valid parameters", function () {
|
describe('with valid parameters', function () {
|
||||||
it("sets the value correctly", function (done) {
|
it('sets the value correctly', function (done) {
|
||||||
client.mset(key, value, key2, value2, function (err) {
|
client.mset(key, value, key2, value2, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return done(err);
|
return done(err);
|
||||||
@@ -67,7 +67,7 @@ describe("The 'mset' method", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("with undefined 'key' parameter and missing 'value' parameter", 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) {
|
client.mset(undefined, function (err, res) {
|
||||||
helper.isError()(err, null);
|
helper.isError()(err, null);
|
||||||
done();
|
done();
|
||||||
@@ -77,15 +77,15 @@ describe("The 'mset' method", function () {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("and no callback is specified", function () {
|
describe('and no callback is specified', function () {
|
||||||
describe("with valid parameters", function () {
|
describe('with valid parameters', function () {
|
||||||
it("sets the value correctly", function (done) {
|
it('sets the value correctly', function (done) {
|
||||||
client.mset(key, value2, key2, value);
|
client.mset(key, value2, key2, value);
|
||||||
client.get(key, helper.isString(value2));
|
client.get(key, helper.isString(value2));
|
||||||
client.get(key2, helper.isString(value, done));
|
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.mset([key, value2, key2, value]);
|
||||||
client.get(key, helper.isString(value2));
|
client.get(key, helper.isString(value2));
|
||||||
client.get(key2, helper.isString(value, done));
|
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 () {
|
describe("with undefined 'key' and missing 'value' parameter", function () {
|
||||||
// this behavior is different from the 'set' behavior.
|
// 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) {
|
client.on('error', function (err) {
|
||||||
assert.equal(err.message, "ERR wrong number of arguments for 'mset' command");
|
assert.equal(err.message, "ERR wrong number of arguments for 'mset' command");
|
||||||
done();
|
done();
|
||||||
|
@@ -1,33 +1,33 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var helper = require("../helper");
|
var helper = require('../helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
describe("The 'msetnx' method", function () {
|
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;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.flushdb(done);
|
client.flushdb(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('if any keys exist entire operation fails', function (done) {
|
it('if any keys exist entire operation fails', function (done) {
|
||||||
client.mset(["mset1", "val1", "mset2", "val2", "mset3", "val3"], helper.isString("OK"));
|
client.mset(['mset1', 'val1', 'mset2', 'val2', 'mset3', 'val3'], helper.isString('OK'));
|
||||||
client.MSETNX(["mset3", "val3", "mset4", "val4"], helper.isNumber(0));
|
client.MSETNX(['mset3', 'val3', 'mset4', 'val4'], helper.isNumber(0));
|
||||||
client.exists(["mset4"], helper.isNumber(0, done));
|
client.exists(['mset4'], helper.isNumber(0, done));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sets multiple keys if all keys are not set', function (done) {
|
it('sets multiple keys if all keys are not set', function (done) {
|
||||||
client.msetnx(["mset3", "val3", "mset4", "val4"], helper.isNumber(1));
|
client.msetnx(['mset3', 'val3', 'mset4', 'val4'], helper.isNumber(1));
|
||||||
client.exists(["mset3"], helper.isNumber(1));
|
client.exists(['mset3'], helper.isNumber(1));
|
||||||
client.exists(["mset3"], helper.isNumber(1, done));
|
client.exists(['mset3'], helper.isNumber(1, done));
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(function () {
|
||||||
|
@@ -1,26 +1,26 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require("assert");
|
var assert = require('assert');
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var helper = require("../helper");
|
var helper = require('../helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
describe("The 'randomkey' method", function () {
|
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;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.flushdb(done);
|
client.flushdb(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns a random key', function (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) {
|
client.RANDOMKEY([], function (err, results) {
|
||||||
assert.strictEqual(true, /test keys.+/.test(results));
|
assert.strictEqual(true, /test keys.+/.test(results));
|
||||||
return done(err);
|
return done(err);
|
||||||
|
@@ -1,33 +1,33 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var helper = require("../helper");
|
var helper = require('../helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
describe("The 'rename' method", function () {
|
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;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.flushdb(done);
|
client.flushdb(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('populates the new key', function (done) {
|
it('populates the new key', function (done) {
|
||||||
client.set(['foo', 'bar'], helper.isString("OK"));
|
client.set(['foo', 'bar'], helper.isString('OK'));
|
||||||
client.rename(["foo", "new foo"], helper.isString("OK"));
|
client.rename(['foo', 'new foo'], helper.isString('OK'));
|
||||||
client.exists(["new foo"], helper.isNumber(1, done));
|
client.exists(['new foo'], helper.isNumber(1, done));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('removes the old key', function (done) {
|
it('removes the old key', function (done) {
|
||||||
client.set(['foo', 'bar'], helper.isString("OK"));
|
client.set(['foo', 'bar'], helper.isString('OK'));
|
||||||
client.RENAME(["foo", "new foo"], helper.isString("OK"));
|
client.RENAME(['foo', 'new foo'], helper.isString('OK'));
|
||||||
client.exists(["foo"], helper.isNumber(0, done));
|
client.exists(['foo'], helper.isNumber(0, done));
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(function () {
|
||||||
|
@@ -1,19 +1,19 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var helper = require("../helper");
|
var helper = require('../helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
describe("The 'renamenx' method", function () {
|
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;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.flushdb(done);
|
client.flushdb(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var helper = require("../helper");
|
var helper = require('../helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
|
|
||||||
@@ -9,12 +9,12 @@ 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;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.flushdb(done);
|
client.flushdb(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -1,20 +1,20 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require("assert");
|
var assert = require('assert');
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var helper = require("../helper");
|
var helper = require('../helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
describe("The 'sadd' method", function () {
|
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;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.flushdb(done);
|
client.flushdb(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -33,23 +33,23 @@ describe("The 'sadd' method", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('allows multiple values to be added to the set', function (done) {
|
it('allows multiple values to be added to the set', function (done) {
|
||||||
client.sadd("set0", ["member0", "member1", "member2"], helper.isNumber(3));
|
client.sadd('set0', ['member0', 'member1', 'member2'], helper.isNumber(3));
|
||||||
client.smembers("set0", function (err, res) {
|
client.smembers('set0', function (err, res) {
|
||||||
assert.strictEqual(res.length, 3);
|
assert.strictEqual(res.length, 3);
|
||||||
assert.ok(~res.indexOf("member0"));
|
assert.ok(~res.indexOf('member0'));
|
||||||
assert.ok(~res.indexOf("member1"));
|
assert.ok(~res.indexOf('member1'));
|
||||||
assert.ok(~res.indexOf("member2"));
|
assert.ok(~res.indexOf('member2'));
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('allows multiple values to be added to the set with a different syntax', function (done) {
|
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.sadd(['set0', 'member0', 'member1', 'member2'], helper.isNumber(3));
|
||||||
client.smembers("set0", function (err, res) {
|
client.smembers('set0', function (err, res) {
|
||||||
assert.strictEqual(res.length, 3);
|
assert.strictEqual(res.length, 3);
|
||||||
assert.ok(~res.indexOf("member0"));
|
assert.ok(~res.indexOf('member0'));
|
||||||
assert.ok(~res.indexOf("member1"));
|
assert.ok(~res.indexOf('member1'));
|
||||||
assert.ok(~res.indexOf("member2"));
|
assert.ok(~res.indexOf('member2'));
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -1,19 +1,19 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var helper = require("../helper");
|
var helper = require('../helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
describe("The 'scard' method", function () {
|
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;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.flushdb(done);
|
client.flushdb(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -1,23 +1,23 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require("assert");
|
var assert = require('assert');
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var crypto = require("crypto");
|
var crypto = require('crypto');
|
||||||
var helper = require("../helper");
|
var helper = require('../helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
describe("The 'script' method", function () {
|
describe("The 'script' method", function () {
|
||||||
|
|
||||||
helper.allTests(function (parser, ip, args) {
|
helper.allTests(function (parser, ip, args) {
|
||||||
var command = "return 99";
|
var command = 'return 99';
|
||||||
var commandSha = crypto.createHash('sha1').update(command).digest('hex');
|
var commandSha = crypto.createHash('sha1').update(command).digest('hex');
|
||||||
|
|
||||||
describe("using " + parser + " and " + ip, function () {
|
describe('using ' + parser + ' and ' + ip, function () {
|
||||||
var client;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.flushdb(done);
|
client.flushdb(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -27,7 +27,7 @@ describe("The 'script' method", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("loads script with client.script('load')", function (done) {
|
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);
|
assert.strictEqual(result, commandSha);
|
||||||
return done();
|
return done();
|
||||||
});
|
});
|
||||||
@@ -38,7 +38,7 @@ describe("The 'script' method", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('allows a script to be loaded as part of a chained transaction', function (done) {
|
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);
|
assert.strictEqual(result[0], commandSha);
|
||||||
return done();
|
return done();
|
||||||
});
|
});
|
||||||
|
@@ -1,20 +1,20 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require("assert");
|
var assert = require('assert');
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var helper = require("../helper");
|
var helper = require('../helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
describe("The 'sdiff' method", function () {
|
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;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.flushdb(done);
|
client.flushdb(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -1,20 +1,20 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require("assert");
|
var assert = require('assert');
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var helper = require("../helper");
|
var helper = require('../helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
describe("The 'sdiffstore' method", function () {
|
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;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.flushdb(done);
|
client.flushdb(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var helper = require('../helper');
|
var helper = require('../helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
@@ -9,19 +9,19 @@ describe("The 'select' 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 () {
|
||||||
describe("when not connected", function () {
|
describe('when not connected', function () {
|
||||||
var client;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.quit();
|
client.quit();
|
||||||
});
|
});
|
||||||
client.on('end', done);
|
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) {
|
var buffering = client.select(1, function (err, res) {
|
||||||
assert(err.message.match(/The connection has already been closed/));
|
assert(err.message.match(/The connection has already been closed/));
|
||||||
done();
|
done();
|
||||||
@@ -30,12 +30,12 @@ describe("The 'select' method", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when connected", function () {
|
describe('when connected', function () {
|
||||||
var client;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.flushdb(done);
|
client.flushdb(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -44,32 +44,32 @@ describe("The 'select' method", function () {
|
|||||||
client.end(true);
|
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.
|
// 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) {
|
var buffering = client.SELECT(1, function (err, res) {
|
||||||
helper.isNotError()(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();
|
done();
|
||||||
});
|
});
|
||||||
assert(typeof buffering === 'boolean');
|
assert(typeof buffering === 'boolean');
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("and a callback is specified", function () {
|
describe('and a callback is specified', function () {
|
||||||
describe("with a valid db index", function () {
|
describe('with a valid db index', function () {
|
||||||
it("selects the appropriate database", function (done) {
|
it('selects the appropriate database', function (done) {
|
||||||
assert.strictEqual(client.selected_db, undefined, "default db should be undefined");
|
assert.strictEqual(client.selected_db, undefined, 'default db should be undefined');
|
||||||
client.select(1, function (err) {
|
client.select(1, function (err) {
|
||||||
assert.equal(err, null);
|
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();
|
return done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("with an invalid db index", function () {
|
describe('with an invalid db index', function () {
|
||||||
it("returns an error", function (done) {
|
it('returns an error', function (done) {
|
||||||
assert.strictEqual(client.selected_db, undefined, "default db should be undefined");
|
assert.strictEqual(client.selected_db, undefined, 'default db should be undefined');
|
||||||
client.select(9999, function (err) {
|
client.select(9999, function (err) {
|
||||||
assert.equal(err.code, 'ERR');
|
assert.equal(err.code, 'ERR');
|
||||||
assert.equal(err.message, 'ERR invalid DB index');
|
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('and no callback is specified', function () {
|
||||||
describe("with a valid db index", function () {
|
describe('with a valid db index', function () {
|
||||||
it("selects the appropriate database", function (done) {
|
it('selects the appropriate database', function (done) {
|
||||||
assert.strictEqual(client.selected_db, undefined, "default db should be undefined");
|
assert.strictEqual(client.selected_db, undefined, 'default db should be undefined');
|
||||||
client.select(1);
|
client.select(1);
|
||||||
setTimeout(function () {
|
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();
|
return done();
|
||||||
}, 100);
|
}, 100);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("with an invalid db index", function () {
|
describe('with an invalid db index', function () {
|
||||||
it("emits an error when callback not provided", function (done) {
|
it('emits an error when callback not provided', function (done) {
|
||||||
assert.strictEqual(client.selected_db, undefined, "default db should be undefined");
|
assert.strictEqual(client.selected_db, undefined, 'default db should be undefined');
|
||||||
|
|
||||||
client.on('error', function (err) {
|
client.on('error', function (err) {
|
||||||
assert.strictEqual(err.command, 'SELECT');
|
assert.strictEqual(err.command, 'SELECT');
|
||||||
@@ -106,9 +106,9 @@ describe("The 'select' method", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("reconnection occurs", function () {
|
describe('reconnection occurs', function () {
|
||||||
it("selects the appropriate database after a reconnect", function (done) {
|
it('selects the appropriate database after a reconnect', function (done) {
|
||||||
assert.strictEqual(client.selected_db, undefined, "default db should be undefined");
|
assert.strictEqual(client.selected_db, undefined, 'default db should be undefined');
|
||||||
client.select(3);
|
client.select(3);
|
||||||
client.set('foo', 'bar', function () {
|
client.set('foo', 'bar', function () {
|
||||||
client.stream.destroy();
|
client.stream.destroy();
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var helper = require('../helper');
|
var helper = require('../helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
var uuid = require('uuid');
|
var uuid = require('uuid');
|
||||||
@@ -10,7 +10,7 @@ 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;
|
var key, value;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
@@ -18,18 +18,18 @@ describe("The 'set' method", function () {
|
|||||||
value = uuid.v4();
|
value = uuid.v4();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when not connected", function () {
|
describe('when not connected', function () {
|
||||||
var client;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.quit();
|
client.quit();
|
||||||
});
|
});
|
||||||
client.on('end', done);
|
client.on('end', done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("reports an error", function (done) {
|
it('reports an error', function (done) {
|
||||||
client.set(key, value, function (err, res) {
|
client.set(key, value, function (err, res) {
|
||||||
assert(err.message.match(/The connection has already been closed/));
|
assert(err.message.match(/The connection has already been closed/));
|
||||||
done();
|
done();
|
||||||
@@ -37,12 +37,12 @@ describe("The 'set' method", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when connected", function () {
|
describe('when connected', function () {
|
||||||
var client;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -51,9 +51,9 @@ describe("The 'set' method", function () {
|
|||||||
client.end(true);
|
client.end(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("and a callback is specified", function () {
|
describe('and a callback is specified', function () {
|
||||||
describe("with valid parameters", function () {
|
describe('with valid parameters', function () {
|
||||||
it("sets the value correctly", function (done) {
|
it('sets the value correctly', function (done) {
|
||||||
client.SET(key, value, function (err, res) {
|
client.SET(key, value, function (err, res) {
|
||||||
helper.isNotError()(err, res);
|
helper.isNotError()(err, res);
|
||||||
client.get(key, function (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) {
|
it("undefined 'key' and missing 'value' parameter", function (done) {
|
||||||
client.set(undefined, function (err, res) {
|
client.set(undefined, function (err, res) {
|
||||||
helper.isError()(err, null);
|
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) {
|
client.set('foo', [], function (err, res) {
|
||||||
assert.strictEqual(err.message, "ERR wrong number of arguments for 'set' command");
|
assert.strictEqual(err.message, "ERR wrong number of arguments for 'set' command");
|
||||||
done();
|
done();
|
||||||
@@ -82,26 +82,26 @@ describe("The 'set' method", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("and no callback is specified", function () {
|
describe('and no callback is specified', function () {
|
||||||
describe("with valid parameters", function () {
|
describe('with valid parameters', function () {
|
||||||
it("sets the value correctly", function (done) {
|
it('sets the value correctly', function (done) {
|
||||||
client.set(key, value);
|
client.set(key, value);
|
||||||
client.get(key, helper.isString(value, done));
|
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.set(key, value, undefined);
|
||||||
client.get(key, helper.isString(value, done));
|
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.set([key, value]);
|
||||||
client.get(key, helper.isString(value, done));
|
client.get(key, helper.isString(value, done));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("with undefined 'key' and missing 'value' parameter", function () {
|
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) {
|
client.on('error', function (err) {
|
||||||
assert.equal(err.message, "ERR wrong number of arguments for 'set' command");
|
assert.equal(err.message, "ERR wrong number of arguments for 'set' command");
|
||||||
assert.equal(err.command, 'SET');
|
assert.equal(err.command, 'SET');
|
||||||
@@ -117,7 +117,7 @@ describe("The 'set' method", function () {
|
|||||||
client.get('foo', helper.isString('null', done));
|
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) {
|
client.on('error', function (err) {
|
||||||
assert.equal(err.message, "ERR wrong number of arguments for 'set' command");
|
assert.equal(err.message, "ERR wrong number of arguments for 'set' command");
|
||||||
done();
|
done();
|
||||||
@@ -126,8 +126,8 @@ describe("The 'set' method", function () {
|
|||||||
client.set('foo');
|
client.set('foo');
|
||||||
});
|
});
|
||||||
|
|
||||||
it("emit an error without any parameters", function (done) {
|
it('emit an error without any parameters', function (done) {
|
||||||
client.once("error", function (err) {
|
client.once('error', function (err) {
|
||||||
assert.equal(err.message, "ERR wrong number of arguments for 'set' command");
|
assert.equal(err.message, "ERR wrong number of arguments for 'set' command");
|
||||||
assert.equal(err.command, 'SET');
|
assert.equal(err.command, 'SET');
|
||||||
done();
|
done();
|
||||||
|
@@ -1,27 +1,27 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require("assert");
|
var assert = require('assert');
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var helper = require("../helper");
|
var helper = require('../helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
describe("The 'setex' method", function () {
|
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;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.flushdb(done);
|
client.flushdb(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sets a key with an expiry', function (done) {
|
it('sets a key with an expiry', function (done) {
|
||||||
client.setex(["setex key", "100", "setex val"], helper.isString("OK"));
|
client.setex(['setex key', '100', 'setex val'], helper.isString('OK'));
|
||||||
var buffering = client.exists(["setex key"], helper.isNumber(1));
|
var buffering = client.exists(['setex key'], helper.isNumber(1));
|
||||||
assert(typeof buffering === 'boolean');
|
assert(typeof buffering === 'boolean');
|
||||||
client.ttl(['setex key'], function (err, ttl) {
|
client.ttl(['setex key'], function (err, ttl) {
|
||||||
assert(ttl > 0);
|
assert(ttl > 0);
|
||||||
|
@@ -1,19 +1,19 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var helper = require("../helper");
|
var helper = require('../helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
describe("The 'setnx' method", function () {
|
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;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.flushdb(done);
|
client.flushdb(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -1,20 +1,20 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require("assert");
|
var assert = require('assert');
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var helper = require("../helper");
|
var helper = require('../helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
describe("The 'sinter' method", function () {
|
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;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.flushdb(done);
|
client.flushdb(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -1,20 +1,20 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require("assert");
|
var assert = require('assert');
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var helper = require("../helper");
|
var helper = require('../helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
describe("The 'sinterstore' method", function () {
|
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;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.flushdb(done);
|
client.flushdb(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -1,19 +1,19 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var helper = require("../helper");
|
var helper = require('../helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
describe("The 'sismember' method", function () {
|
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;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.flushdb(done);
|
client.flushdb(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -1,34 +1,34 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require("assert");
|
var assert = require('assert');
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var helper = require("../helper");
|
var helper = require('../helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
describe("The 'slowlog' method", function () {
|
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;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.flushdb(done);
|
client.flushdb(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('logs operations in slowlog', function (done) {
|
it('logs operations in slowlog', function (done) {
|
||||||
client.config("set", "slowlog-log-slower-than", 0, helper.isString("OK"));
|
client.config('set', 'slowlog-log-slower-than', 0, helper.isString('OK'));
|
||||||
client.slowlog("reset", helper.isString("OK"));
|
client.slowlog('reset', helper.isString('OK'));
|
||||||
client.set("foo", "bar", helper.isString("OK"));
|
client.set('foo', 'bar', helper.isString('OK'));
|
||||||
client.get("foo", helper.isString("bar"));
|
client.get('foo', helper.isString('bar'));
|
||||||
client.SLOWLOG("get", function (err, res) {
|
client.SLOWLOG('get', function (err, res) {
|
||||||
assert.equal(res.length, 3);
|
assert.equal(res.length, 3);
|
||||||
assert.equal(res[0][3].length, 2);
|
assert.equal(res[0][3].length, 2);
|
||||||
assert.deepEqual(res[1][3], ["set", "foo", "bar"]);
|
assert.deepEqual(res[1][3], ['set', 'foo', 'bar']);
|
||||||
assert.deepEqual(res[2][3], ["slowlog", "reset"]);
|
assert.deepEqual(res[2][3], ['slowlog', 'reset']);
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -1,20 +1,20 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require("assert");
|
var assert = require('assert');
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var helper = require("../helper");
|
var helper = require('../helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
describe("The 'smembers' method", function () {
|
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;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.flushdb(done);
|
client.flushdb(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -1,19 +1,19 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var helper = require("../helper");
|
var helper = require('../helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
describe("The 'smove' method", function () {
|
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;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.flushdb(done);
|
client.flushdb(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -25,7 +25,7 @@ describe("The 'smove' method", function () {
|
|||||||
client.sismember('bar', 'x', helper.isNumber(1, done));
|
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.sadd('foo', 'x', helper.isNumber(1));
|
||||||
client.SMOVE('foo', 'bar', 'y', helper.isNumber(0));
|
client.SMOVE('foo', 'bar', 'y', helper.isNumber(0));
|
||||||
client.sismember('foo', 'y', helper.isNumber(0));
|
client.sismember('foo', 'y', helper.isNumber(0));
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require("assert");
|
var assert = require('assert');
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var helper = require("../helper");
|
var helper = require('../helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
function setupData (client, done) {
|
function setupData (client, done) {
|
||||||
@@ -36,13 +36,13 @@ 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;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("error", done);
|
client.once('error', done);
|
||||||
client.once("connect", function () {
|
client.once('connect', function () {
|
||||||
client.flushdb();
|
client.flushdb();
|
||||||
setupData(client, done);
|
setupData(client, done);
|
||||||
});
|
});
|
||||||
|
@@ -1,20 +1,20 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require("assert");
|
var assert = require('assert');
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var helper = require("../helper");
|
var helper = require('../helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
describe("The 'spop' method", function () {
|
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;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.flushdb(done);
|
client.flushdb(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -1,20 +1,20 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require("assert");
|
var assert = require('assert');
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var helper = require("../helper");
|
var helper = require('../helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
describe("The 'srem' method", function () {
|
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;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.flushdb(done);
|
client.flushdb(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -30,33 +30,33 @@ describe("The 'srem' method", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('allows multiple values to be removed', function (done) {
|
it('allows multiple values to be removed', function (done) {
|
||||||
client.sadd("set0", ["member0", "member1", "member2"], helper.isNumber(3));
|
client.sadd('set0', ['member0', 'member1', 'member2'], helper.isNumber(3));
|
||||||
client.SREM("set0", ["member1", "member2"], helper.isNumber(2));
|
client.SREM('set0', ['member1', 'member2'], helper.isNumber(2));
|
||||||
client.smembers("set0", function (err, res) {
|
client.smembers('set0', function (err, res) {
|
||||||
assert.strictEqual(res.length, 1);
|
assert.strictEqual(res.length, 1);
|
||||||
assert.ok(~res.indexOf("member0"));
|
assert.ok(~res.indexOf('member0'));
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('allows multiple values to be removed with send_command', function (done) {
|
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('sadd', ['set0', 'member0', 'member1', 'member2'], helper.isNumber(3));
|
||||||
client.send_command('srem', ["set0", "member1", "member2"], helper.isNumber(2));
|
client.send_command('srem', ['set0', 'member1', 'member2'], helper.isNumber(2));
|
||||||
client.smembers("set0", function (err, res) {
|
client.smembers('set0', function (err, res) {
|
||||||
assert.strictEqual(res.length, 1);
|
assert.strictEqual(res.length, 1);
|
||||||
assert.ok(~res.indexOf("member0"));
|
assert.ok(~res.indexOf('member0'));
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles a value missing from the set of values being removed', function (done) {
|
it('handles a value missing from the set of values being removed', function (done) {
|
||||||
client.sadd(["set0", "member0", "member1", "member2"], helper.isNumber(3));
|
client.sadd(['set0', 'member0', 'member1', 'member2'], helper.isNumber(3));
|
||||||
client.SREM(["set0", "member3", "member4"], helper.isNumber(0));
|
client.SREM(['set0', 'member3', 'member4'], helper.isNumber(0));
|
||||||
client.smembers("set0", function (err, res) {
|
client.smembers('set0', function (err, res) {
|
||||||
assert.strictEqual(res.length, 3);
|
assert.strictEqual(res.length, 3);
|
||||||
assert.ok(~res.indexOf("member0"));
|
assert.ok(~res.indexOf('member0'));
|
||||||
assert.ok(~res.indexOf("member1"));
|
assert.ok(~res.indexOf('member1'));
|
||||||
assert.ok(~res.indexOf("member2"));
|
assert.ok(~res.indexOf('member2'));
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -1,20 +1,20 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require("assert");
|
var assert = require('assert');
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var helper = require("../helper");
|
var helper = require('../helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
describe("The 'sunion' method", function () {
|
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;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.flushdb(done);
|
client.flushdb(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -1,20 +1,20 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require("assert");
|
var assert = require('assert');
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var helper = require("../helper");
|
var helper = require('../helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
describe("The 'sunionstore' method", function () {
|
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;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.flushdb(done);
|
client.flushdb(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -1,29 +1,29 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require("assert");
|
var assert = require('assert');
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var helper = require("../helper");
|
var helper = require('../helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
describe("The 'ttl' method", function () {
|
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;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.flushdb(done);
|
client.flushdb(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns the current ttl on a key', function (done) {
|
it('returns the current ttl on a key', function (done) {
|
||||||
client.set(["ttl key", "ttl val"], helper.isString("OK"));
|
client.set(['ttl key', 'ttl val'], helper.isString('OK'));
|
||||||
client.expire(["ttl key", "100"], helper.isNumber(1));
|
client.expire(['ttl key', '100'], helper.isNumber(1));
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
client.TTL(["ttl key"], function (err, ttl) {
|
client.TTL(['ttl key'], function (err, ttl) {
|
||||||
assert.ok(ttl > 50 && ttl <= 100);
|
assert.ok(ttl > 50 && ttl <= 100);
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
|
@@ -1,50 +1,50 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var helper = require("../helper");
|
var helper = require('../helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
describe("The 'type' method", function () {
|
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;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.flushdb(done);
|
client.flushdb(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('reports string type', function (done) {
|
it('reports string type', function (done) {
|
||||||
client.set(["string key", "should be a string"], helper.isString("OK"));
|
client.set(['string key', 'should be a string'], helper.isString('OK'));
|
||||||
client.TYPE(["string key"], helper.isString("string", done));
|
client.TYPE(['string key'], helper.isString('string', done));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('reports list type', function (done) {
|
it('reports list type', function (done) {
|
||||||
client.rpush(["list key", "should be a list"], helper.isNumber(1));
|
client.rpush(['list key', 'should be a list'], helper.isNumber(1));
|
||||||
client.type(["list key"], helper.isString("list", done));
|
client.type(['list key'], helper.isString('list', done));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('reports set type', function (done) {
|
it('reports set type', function (done) {
|
||||||
client.sadd(["set key", "should be a set"], helper.isNumber(1));
|
client.sadd(['set key', 'should be a set'], helper.isNumber(1));
|
||||||
client.TYPE(["set key"], helper.isString("set", done));
|
client.TYPE(['set key'], helper.isString('set', done));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('reports zset type', function (done) {
|
it('reports zset type', function (done) {
|
||||||
client.zadd("zset key", ["10.0", "should be a zset"], helper.isNumber(1));
|
client.zadd('zset key', ['10.0', 'should be a zset'], helper.isNumber(1));
|
||||||
client.TYPE(["zset key"], helper.isString("zset", done));
|
client.TYPE(['zset key'], helper.isString('zset', done));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('reports hash type', function (done) {
|
it('reports hash type', function (done) {
|
||||||
client.hset("hash key", "hashtest", "should be a hash", helper.isNumber(1));
|
client.hset('hash key', 'hashtest', 'should be a hash', helper.isNumber(1));
|
||||||
client.TYPE(["hash key"], helper.isString("hash", done));
|
client.TYPE(['hash key'], helper.isString('hash', done));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('reports none for null key', function (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 () {
|
afterEach(function () {
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require("assert");
|
var assert = require('assert');
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var helper = require("../helper");
|
var helper = require('../helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
describe("The 'watch' method", function () {
|
describe("The 'watch' method", function () {
|
||||||
@@ -11,12 +11,12 @@ describe("The 'watch' method", function () {
|
|||||||
|
|
||||||
var watched = 'foobar';
|
var watched = 'foobar';
|
||||||
|
|
||||||
describe("using " + parser + " and " + ip, function () {
|
describe('using ' + parser + ' and ' + ip, function () {
|
||||||
var client;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.flushdb(done);
|
client.flushdb(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -34,17 +34,17 @@ describe("The 'watch' method", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('successfully modifies other keys independently of transaction', function (done) {
|
it('successfully modifies other keys independently of transaction', function (done) {
|
||||||
client.set("unwatched", 200);
|
client.set('unwatched', 200);
|
||||||
|
|
||||||
client.set(watched, 0);
|
client.set(watched, 0);
|
||||||
client.watch(watched);
|
client.watch(watched);
|
||||||
client.incr(watched);
|
client.incr(watched);
|
||||||
|
|
||||||
client.multi().incr(watched).exec(function (err, replies) {
|
client.multi().incr(watched).exec(function (err, replies) {
|
||||||
assert.strictEqual(replies, null, "Aborted transaction multi-bulk reply should be null.");
|
assert.strictEqual(replies, null, 'Aborted transaction multi-bulk reply should be null.');
|
||||||
|
|
||||||
client.get("unwatched", function (err, reply) {
|
client.get('unwatched', function (err, reply) {
|
||||||
assert.equal(reply, 200, "Expected 200, got " + reply);
|
assert.equal(reply, 200, 'Expected 200, got ' + reply);
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var helper = require("../helper");
|
var helper = require('../helper');
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
@@ -9,28 +9,28 @@ 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;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.flushdb(done);
|
client.flushdb(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('reports an error', function (done) {
|
it('reports an error', function (done) {
|
||||||
if (helper.redisProcess().spawnFailed()) this.skip();
|
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) {
|
it('return inf / -inf', function (done) {
|
||||||
if (helper.redisProcess().spawnFailed()) this.skip();
|
if (helper.redisProcess().spawnFailed()) this.skip();
|
||||||
helper.serverVersionAtLeast.call(this, client, [3, 0, 2]);
|
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', ['inf', 'should be also be inf'], helper.isNumber(1));
|
||||||
client.zadd('infinity', -Infinity, "should be negative 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', [99999999999999999999999, 'should not be inf'], helper.isNumber(1));
|
||||||
client.zrange('infinity', 0, -1, 'WITHSCORES', function (err, res) {
|
client.zrange('infinity', 0, -1, 'WITHSCORES', function (err, res) {
|
||||||
assert.equal(res[5], 'inf');
|
assert.equal(res[5], 'inf');
|
||||||
assert.equal(res[1], '-inf');
|
assert.equal(res[1], '-inf');
|
||||||
|
@@ -9,12 +9,12 @@ 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;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.flushdb(done);
|
client.flushdb(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -24,14 +24,14 @@ describe("The 'zscan' method", function () {
|
|||||||
helper.serverVersionAtLeast.call(this, client, [2, 8, 0]);
|
helper.serverVersionAtLeast.call(this, client, [2, 8, 0]);
|
||||||
var hash = {};
|
var hash = {};
|
||||||
var set = [];
|
var set = [];
|
||||||
var zset = ["zset:1"];
|
var zset = ['zset:1'];
|
||||||
for (var i = 0; i < 500; i++) {
|
for (var i = 0; i < 500; i++) {
|
||||||
hash["key_" + i] = "value_" + i;
|
hash['key_' + i] = 'value_' + i;
|
||||||
set.push("member_" + i);
|
set.push('member_' + i);
|
||||||
zset.push(i, "z_member_" + i);
|
zset.push(i, 'z_member_' + i);
|
||||||
}
|
}
|
||||||
client.hmset("hash:1", hash);
|
client.hmset('hash:1', hash);
|
||||||
client.sadd("set:1", set);
|
client.sadd('set:1', set);
|
||||||
client.zadd(zset);
|
client.zadd(zset);
|
||||||
client.zscan('zset:1', 0, 'MATCH', '*', 'COUNT', 500, function (err, res) {
|
client.zscan('zset:1', 0, 'MATCH', '*', 'COUNT', 500, function (err, res) {
|
||||||
assert(!err);
|
assert(!err);
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var config = require("../lib/config");
|
var config = require('../lib/config');
|
||||||
var helper = require("../helper");
|
var helper = require('../helper');
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
@@ -9,12 +9,12 @@ 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;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.flushdb(done);
|
client.flushdb(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -1,9 +1,9 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require("assert");
|
var assert = require('assert');
|
||||||
var config = require("./lib/config");
|
var config = require('./lib/config');
|
||||||
var helper = require('./helper');
|
var helper = require('./helper');
|
||||||
var RedisProcess = require("./lib/redis-process");
|
var RedisProcess = require('./lib/redis-process');
|
||||||
var rp;
|
var rp;
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
@@ -38,7 +38,7 @@ describe('master slave sync', function () {
|
|||||||
multi.exec(done);
|
multi.exec(done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("sync process and no master should delay ready being emitted for slaves", function (done) {
|
it('sync process and no master should delay ready being emitted for slaves', function (done) {
|
||||||
if (helper.redisProcess().spawnFailed()) this.skip();
|
if (helper.redisProcess().spawnFailed()) this.skip();
|
||||||
|
|
||||||
var port = 6381;
|
var port = 6381;
|
||||||
|
@@ -1,14 +1,14 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require("assert");
|
var assert = require('assert');
|
||||||
var config = require("./lib/config");
|
var config = require('./lib/config');
|
||||||
var helper = require('./helper');
|
var helper = require('./helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
var intercept = require('intercept-stdout');
|
var intercept = require('intercept-stdout');
|
||||||
var net = require('net');
|
var net = require('net');
|
||||||
var client;
|
var client;
|
||||||
|
|
||||||
describe("connection tests", function () {
|
describe('connection tests', function () {
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
client = null;
|
client = null;
|
||||||
@@ -36,10 +36,10 @@ describe("connection tests", 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 () {
|
||||||
|
|
||||||
describe("on lost connection", function () {
|
describe('on lost connection', function () {
|
||||||
it("emit an error after max retry attempts and do not try to reconnect afterwards", function (done) {
|
it('emit an error after max retry attempts and do not try to reconnect afterwards', function (done) {
|
||||||
var max_attempts = 4;
|
var max_attempts = 4;
|
||||||
var options = {
|
var options = {
|
||||||
parser: parser,
|
parser: parser,
|
||||||
@@ -53,7 +53,7 @@ describe("connection tests", function () {
|
|||||||
helper.killConnection(client);
|
helper.killConnection(client);
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on("reconnecting", function (params) {
|
client.on('reconnecting', function (params) {
|
||||||
calls++;
|
calls++;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -67,7 +67,7 @@ describe("connection tests", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("emit an error after max retry timeout and do not try to reconnect afterwards", function (done) {
|
it('emit an error after max retry timeout and do not try to reconnect afterwards', function (done) {
|
||||||
// TODO: Investigate why this test fails with windows. Reconnect is only triggered once
|
// TODO: Investigate why this test fails with windows. Reconnect is only triggered once
|
||||||
if (process.platform === 'win32') this.skip();
|
if (process.platform === 'win32') this.skip();
|
||||||
|
|
||||||
@@ -82,7 +82,7 @@ describe("connection tests", function () {
|
|||||||
helper.killConnection(client);
|
helper.killConnection(client);
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on("reconnecting", function (params) {
|
client.on('reconnecting', function (params) {
|
||||||
time += params.delay;
|
time += params.delay;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ describe("connection tests", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("end connection while retry is still ongoing", function (done) {
|
it('end connection while retry is still ongoing', function (done) {
|
||||||
var connect_timeout = 1000; // in ms
|
var connect_timeout = 1000; // in ms
|
||||||
client = redis.createClient({
|
client = redis.createClient({
|
||||||
parser: parser,
|
parser: parser,
|
||||||
@@ -108,14 +108,14 @@ describe("connection tests", function () {
|
|||||||
helper.killConnection(client);
|
helper.killConnection(client);
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on("reconnecting", function (params) {
|
client.on('reconnecting', function (params) {
|
||||||
client.end(true);
|
client.end(true);
|
||||||
assert.strictEqual(params.times_connected, 1);
|
assert.strictEqual(params.times_connected, 1);
|
||||||
setTimeout(done, 100);
|
setTimeout(done, 100);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("can not connect with wrong host / port in the options object", function (done) {
|
it('can not connect with wrong host / port in the options object', function (done) {
|
||||||
var options = {
|
var options = {
|
||||||
host: 'somewhere',
|
host: 'somewhere',
|
||||||
port: 6379,
|
port: 6379,
|
||||||
@@ -134,7 +134,7 @@ describe("connection tests", function () {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("emits error once if reconnecting after command has been executed but not yet returned without callback", function (done) {
|
it('emits error once if reconnecting after command has been executed but not yet returned without callback', function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.on('error', function (err) {
|
client.on('error', function (err) {
|
||||||
assert.strictEqual(err.code, 'UNCERTAIN_STATE');
|
assert.strictEqual(err.code, 'UNCERTAIN_STATE');
|
||||||
@@ -142,13 +142,13 @@ describe("connection tests", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
client.on('ready', function () {
|
client.on('ready', function () {
|
||||||
client.set("foo", 'bar');
|
client.set('foo', 'bar');
|
||||||
// Abort connection before the value returned
|
// Abort connection before the value returned
|
||||||
client.stream.destroy();
|
client.stream.destroy();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("retry_strategy used to reconnect with individual error", function (done) {
|
it('retry_strategy used to reconnect with individual error', function (done) {
|
||||||
var text = '';
|
var text = '';
|
||||||
var unhookIntercept = intercept(function (data) {
|
var unhookIntercept = intercept(function (data) {
|
||||||
text += data;
|
text += data;
|
||||||
@@ -185,7 +185,7 @@ describe("connection tests", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("retry_strategy used to reconnect", function (done) {
|
it('retry_strategy used to reconnect', function (done) {
|
||||||
var end = helper.callFuncAfter(done, 2);
|
var end = helper.callFuncAfter(done, 2);
|
||||||
client = redis.createClient({
|
client = redis.createClient({
|
||||||
retry_strategy: function (options) {
|
retry_strategy: function (options) {
|
||||||
@@ -208,9 +208,9 @@ describe("connection tests", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when not connected", function () {
|
describe('when not connected', function () {
|
||||||
|
|
||||||
it("emit an error after the socket timeout exceeded the connect_timeout time", function (done) {
|
it('emit an error after the socket timeout exceeded the connect_timeout time', function (done) {
|
||||||
var connect_timeout = 500; // in ms
|
var connect_timeout = 500; // in ms
|
||||||
var time = Date.now();
|
var time = Date.now();
|
||||||
client = redis.createClient({
|
client = redis.createClient({
|
||||||
@@ -225,7 +225,7 @@ describe("connection tests", function () {
|
|||||||
assert.strictEqual(client.address, '10.255.255.1:6379');
|
assert.strictEqual(client.address, '10.255.255.1:6379');
|
||||||
assert.strictEqual(client.connection_options.family, 4);
|
assert.strictEqual(client.connection_options.family, 4);
|
||||||
|
|
||||||
client.on("reconnecting", function (params) {
|
client.on('reconnecting', function (params) {
|
||||||
throw new Error('No reconnect, since no connection was ever established');
|
throw new Error('No reconnect, since no connection was ever established');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -244,7 +244,7 @@ describe("connection tests", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("use the system socket timeout if the connect_timeout has not been provided", function () {
|
it('use the system socket timeout if the connect_timeout has not been provided', function () {
|
||||||
client = redis.createClient({
|
client = redis.createClient({
|
||||||
parser: parser,
|
parser: parser,
|
||||||
host: '2001:db8::ff00:42:8329' // auto detect ip v6
|
host: '2001:db8::ff00:42:8329' // auto detect ip v6
|
||||||
@@ -256,7 +256,7 @@ describe("connection tests", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("clears the socket timeout after a connection has been established", function (done) {
|
it('clears the socket timeout after a connection has been established', function (done) {
|
||||||
client = redis.createClient({
|
client = redis.createClient({
|
||||||
parser: parser,
|
parser: parser,
|
||||||
connect_timeout: 1000
|
connect_timeout: 1000
|
||||||
@@ -271,7 +271,7 @@ describe("connection tests", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("connect with host and port provided in the options object", function (done) {
|
it('connect with host and port provided in the options object', function (done) {
|
||||||
client = redis.createClient({
|
client = redis.createClient({
|
||||||
host: 'localhost',
|
host: 'localhost',
|
||||||
port: '6379',
|
port: '6379',
|
||||||
@@ -282,7 +282,7 @@ describe("connection tests", function () {
|
|||||||
client.once('ready', done);
|
client.once('ready', done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("connect with path provided in the options object", function (done) {
|
it('connect with path provided in the options object', function (done) {
|
||||||
if (process.platform === 'win32') {
|
if (process.platform === 'win32') {
|
||||||
this.skip();
|
this.skip();
|
||||||
}
|
}
|
||||||
@@ -298,53 +298,53 @@ describe("connection tests", function () {
|
|||||||
client.set('foo', 'bar', end);
|
client.set('foo', 'bar', end);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("connects correctly with args", function (done) {
|
it('connects correctly with args', function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.on("error", done);
|
client.on('error', done);
|
||||||
|
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.removeListener("error", done);
|
client.removeListener('error', done);
|
||||||
client.get("recon 1", done);
|
client.get('recon 1', done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("connects correctly with default values", function (done) {
|
it('connects correctly with default values', function (done) {
|
||||||
client = redis.createClient();
|
client = redis.createClient();
|
||||||
client.on("error", done);
|
client.on('error', done);
|
||||||
|
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.removeListener("error", done);
|
client.removeListener('error', done);
|
||||||
client.get("recon 1", done);
|
client.get('recon 1', done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("connects with a port only", function (done) {
|
it('connects with a port only', function (done) {
|
||||||
client = redis.createClient(6379);
|
client = redis.createClient(6379);
|
||||||
assert.strictEqual(client.connection_options.family, 4);
|
assert.strictEqual(client.connection_options.family, 4);
|
||||||
client.on("error", done);
|
client.on('error', done);
|
||||||
|
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.removeListener("error", done);
|
client.removeListener('error', done);
|
||||||
client.get("recon 1", done);
|
client.get('recon 1', done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("connects correctly to localhost", function (done) {
|
it('connects correctly to localhost', function (done) {
|
||||||
client = redis.createClient(null, null);
|
client = redis.createClient(null, null);
|
||||||
client.on("error", done);
|
client.on('error', done);
|
||||||
|
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.removeListener("error", done);
|
client.removeListener('error', done);
|
||||||
client.get("recon 1", done);
|
client.get('recon 1', done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("connects correctly to the provided host with the port set to null", function (done) {
|
it('connects correctly to the provided host with the port set to null', function (done) {
|
||||||
client = redis.createClient(null, 'localhost');
|
client = redis.createClient(null, 'localhost');
|
||||||
client.on("error", done);
|
client.on('error', done);
|
||||||
assert.strictEqual(client.address, 'localhost:6379');
|
assert.strictEqual(client.address, 'localhost:6379');
|
||||||
|
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.set('foo', 'bar');
|
client.set('foo', 'bar');
|
||||||
client.get('foo', function (err, res) {
|
client.get('foo', function (err, res) {
|
||||||
assert.strictEqual(res, 'bar');
|
assert.strictEqual(res, 'bar');
|
||||||
@@ -353,13 +353,13 @@ describe("connection tests", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("connects correctly to localhost and no ready check", function (done) {
|
it('connects correctly to localhost and no ready check', function (done) {
|
||||||
client = redis.createClient(undefined, undefined, {
|
client = redis.createClient(undefined, undefined, {
|
||||||
no_ready_check: true
|
no_ready_check: true
|
||||||
});
|
});
|
||||||
client.on("error", done);
|
client.on('error', done);
|
||||||
|
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.set('foo', 'bar');
|
client.set('foo', 'bar');
|
||||||
client.get('foo', function (err, res) {
|
client.get('foo', function (err, res) {
|
||||||
assert.strictEqual(res, 'bar');
|
assert.strictEqual(res, 'bar');
|
||||||
@@ -368,14 +368,14 @@ describe("connection tests", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("connects correctly to the provided host with the port set to undefined", function (done) {
|
it('connects correctly to the provided host with the port set to undefined', function (done) {
|
||||||
client = redis.createClient(undefined, 'localhost', {
|
client = redis.createClient(undefined, 'localhost', {
|
||||||
no_ready_check: true
|
no_ready_check: true
|
||||||
});
|
});
|
||||||
client.on("error", done);
|
client.on('error', done);
|
||||||
assert.strictEqual(client.address, 'localhost:6379');
|
assert.strictEqual(client.address, 'localhost:6379');
|
||||||
|
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.set('foo', 'bar');
|
client.set('foo', 'bar');
|
||||||
client.get('foo', function (err, res) {
|
client.get('foo', function (err, res) {
|
||||||
assert.strictEqual(res, 'bar');
|
assert.strictEqual(res, 'bar');
|
||||||
@@ -384,19 +384,19 @@ describe("connection tests", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("connects correctly even if the info command is not present on the redis server", function (done) {
|
it('connects correctly even if the info command is not present on the redis server', function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.info = function (cb) {
|
client.info = function (cb) {
|
||||||
// Mock the result
|
// Mock the result
|
||||||
cb(new Error("ERR unknown command 'info'"));
|
cb(new Error("ERR unknown command 'info'"));
|
||||||
};
|
};
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
assert.strictEqual(Object.keys(client.server_info).length, 0);
|
assert.strictEqual(Object.keys(client.server_info).length, 0);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fake the stream to mock redis", function () {
|
it('fake the stream to mock redis', function () {
|
||||||
// This is needed for libraries that want to mock the stream like fakeredis
|
// This is needed for libraries that want to mock the stream like fakeredis
|
||||||
var temp = redis.RedisClient.prototype.create_stream;
|
var temp = redis.RedisClient.prototype.create_stream;
|
||||||
var create_stream_string = String(temp);
|
var create_stream_string = String(temp);
|
||||||
@@ -418,7 +418,7 @@ describe("connection tests", function () {
|
|||||||
it('allows connecting with the redis url to the default host and port, select db 3 and warn about duplicate db option', function (done) {
|
it('allows connecting with the redis url to the default host and port, select db 3 and warn about duplicate db option', function (done) {
|
||||||
client = redis.createClient('redis:///3?db=3');
|
client = redis.createClient('redis:///3?db=3');
|
||||||
assert.strictEqual(client.selected_db, '3');
|
assert.strictEqual(client.selected_db, '3');
|
||||||
client.on("ready", done);
|
client.on('ready', done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('allows connecting with the redis url and the default port and auth provided even though it is not required', function (done) {
|
it('allows connecting with the redis url and the default port and auth provided even though it is not required', function (done) {
|
||||||
@@ -428,7 +428,7 @@ describe("connection tests", function () {
|
|||||||
assert.strictEqual(msg, 'Warning: Redis server does not require a password, but a password was supplied.');
|
assert.strictEqual(msg, 'Warning: Redis server does not require a password, but a password was supplied.');
|
||||||
end();
|
end();
|
||||||
});
|
});
|
||||||
client.on("ready", end);
|
client.on('ready', end);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('allows connecting with the redis url as first parameter and the options as second parameter', function (done) {
|
it('allows connecting with the redis url as first parameter and the options as second parameter', function (done) {
|
||||||
@@ -447,7 +447,7 @@ describe("connection tests", function () {
|
|||||||
assert.strictEqual(+client.selected_db, 3);
|
assert.strictEqual(+client.selected_db, 3);
|
||||||
assert(!client.options.port);
|
assert(!client.options.port);
|
||||||
assert.strictEqual(client.options.host, config.HOST[ip]);
|
assert.strictEqual(client.options.host, config.HOST[ip]);
|
||||||
client.on("ready", done);
|
client.on('ready', done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('allows connecting with the redis url and no auth and options as second parameter', function (done) {
|
it('allows connecting with the redis url and no auth and options as second parameter', function (done) {
|
||||||
@@ -456,18 +456,18 @@ describe("connection tests", function () {
|
|||||||
};
|
};
|
||||||
client = redis.createClient('redis://' + config.HOST[ip] + ':' + config.PORT, options);
|
client = redis.createClient('redis://' + config.HOST[ip] + ':' + config.PORT, options);
|
||||||
assert.strictEqual(Object.keys(options).length, 1);
|
assert.strictEqual(Object.keys(options).length, 1);
|
||||||
client.on("ready", done);
|
client.on('ready', done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('allows connecting with the redis url and no auth and options as third parameter', function (done) {
|
it('allows connecting with the redis url and no auth and options as third parameter', function (done) {
|
||||||
client = redis.createClient('redis://' + config.HOST[ip] + ':' + config.PORT, null, {
|
client = redis.createClient('redis://' + config.HOST[ip] + ':' + config.PORT, null, {
|
||||||
detect_buffers: false
|
detect_buffers: false
|
||||||
});
|
});
|
||||||
client.on("ready", done);
|
client.on('ready', done);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
it("redis still loading <= 1000ms", function (done) {
|
it('redis still loading <= 1000ms', function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
var tmp = client.info.bind(client);
|
var tmp = client.info.bind(client);
|
||||||
var end = helper.callFuncAfter(done, 3);
|
var end = helper.callFuncAfter(done, 3);
|
||||||
@@ -487,7 +487,7 @@ describe("connection tests", function () {
|
|||||||
cb(err, res);
|
cb(err, res);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
client.on("ready", function () {
|
client.on('ready', function () {
|
||||||
var rest = Date.now() - time;
|
var rest = Date.now() - time;
|
||||||
assert(rest >= 498, 'Rest should be equal or above 500 ms but is: ' + rest); // setTimeout might trigger early
|
assert(rest >= 498, 'Rest should be equal or above 500 ms but is: ' + rest); // setTimeout might trigger early
|
||||||
// Be on the safe side and accept 200ms above the original value
|
// Be on the safe side and accept 200ms above the original value
|
||||||
@@ -497,7 +497,7 @@ describe("connection tests", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("redis still loading > 1000ms", function (done) {
|
it('redis still loading > 1000ms', function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
var tmp = client.info.bind(client);
|
var tmp = client.info.bind(client);
|
||||||
var end = helper.callFuncAfter(done, 3);
|
var end = helper.callFuncAfter(done, 3);
|
||||||
@@ -518,7 +518,7 @@ describe("connection tests", function () {
|
|||||||
cb(err, res);
|
cb(err, res);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
client.on("ready", function () {
|
client.on('ready', function () {
|
||||||
var rest = Date.now() - time;
|
var rest = Date.now() - time;
|
||||||
assert(rest >= 998, '`rest` should be equal or above 1000 ms but is: ' + rest); // setTimeout might trigger early
|
assert(rest >= 998, '`rest` should be equal or above 1000 ms but is: ' + rest); // setTimeout might trigger early
|
||||||
// Be on the safe side and accept 200ms above the original value
|
// Be on the safe side and accept 200ms above the original value
|
||||||
|
@@ -1,15 +1,15 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require("assert");
|
var assert = require('assert');
|
||||||
var config = require("./lib/config");
|
var config = require('./lib/config');
|
||||||
var helper = require('./helper');
|
var helper = require('./helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
describe("detect_buffers", function () {
|
describe('detect_buffers', 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 client;
|
||||||
var args = config.configureClient(parser, ip, {
|
var args = config.configureClient(parser, ip, {
|
||||||
detect_buffers: true
|
detect_buffers: true
|
||||||
@@ -17,11 +17,11 @@ describe("detect_buffers", function () {
|
|||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("error", done);
|
client.once('error', done);
|
||||||
client.once("connect", function () {
|
client.once('connect', function () {
|
||||||
client.flushdb(function (err) {
|
client.flushdb(function (err) {
|
||||||
client.hmset("hash key 2", "key 1", "val 1", "key 2", "val 2");
|
client.hmset('hash key 2', 'key 1', 'val 1', 'key 2', 'val 2');
|
||||||
client.set("string key 1", "string value");
|
client.set('string key 1', 'string value');
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -34,28 +34,28 @@ describe("detect_buffers", function () {
|
|||||||
describe('get', function () {
|
describe('get', function () {
|
||||||
describe('first argument is a string', function () {
|
describe('first argument is a string', function () {
|
||||||
it('returns a string', function (done) {
|
it('returns a string', function (done) {
|
||||||
client.get("string key 1", helper.isString("string value", done));
|
client.get('string key 1', helper.isString('string value', done));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns a string when executed as part of transaction', function (done) {
|
it('returns a string when executed as part of transaction', function (done) {
|
||||||
client.multi().get("string key 1").exec(helper.isString("string value", done));
|
client.multi().get('string key 1').exec(helper.isString('string value', done));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('first argument is a buffer', function () {
|
describe('first argument is a buffer', function () {
|
||||||
it('returns a buffer', function (done) {
|
it('returns a buffer', function (done) {
|
||||||
client.get(new Buffer("string key 1"), function (err, reply) {
|
client.get(new Buffer('string key 1'), function (err, reply) {
|
||||||
assert.strictEqual(true, Buffer.isBuffer(reply));
|
assert.strictEqual(true, Buffer.isBuffer(reply));
|
||||||
assert.strictEqual("<Buffer 73 74 72 69 6e 67 20 76 61 6c 75 65>", reply.inspect());
|
assert.strictEqual('<Buffer 73 74 72 69 6e 67 20 76 61 6c 75 65>', reply.inspect());
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns a bufffer when executed as part of transaction', function (done) {
|
it('returns a bufffer when executed as part of transaction', function (done) {
|
||||||
client.multi().get(new Buffer("string key 1")).exec(function (err, reply) {
|
client.multi().get(new Buffer('string key 1')).exec(function (err, reply) {
|
||||||
assert.strictEqual(1, reply.length);
|
assert.strictEqual(1, reply.length);
|
||||||
assert.strictEqual(true, Buffer.isBuffer(reply[0]));
|
assert.strictEqual(true, Buffer.isBuffer(reply[0]));
|
||||||
assert.strictEqual("<Buffer 73 74 72 69 6e 67 20 76 61 6c 75 65>", reply[0].inspect());
|
assert.strictEqual('<Buffer 73 74 72 69 6e 67 20 76 61 6c 75 65>', reply[0].inspect());
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -65,19 +65,19 @@ describe("detect_buffers", function () {
|
|||||||
describe('multi.hget', function () {
|
describe('multi.hget', function () {
|
||||||
it('can interleave string and buffer results', function (done) {
|
it('can interleave string and buffer results', function (done) {
|
||||||
client.multi()
|
client.multi()
|
||||||
.hget("hash key 2", "key 1")
|
.hget('hash key 2', 'key 1')
|
||||||
.hget(new Buffer("hash key 2"), "key 1")
|
.hget(new Buffer('hash key 2'), 'key 1')
|
||||||
.hget("hash key 2", new Buffer("key 2"))
|
.hget('hash key 2', new Buffer('key 2'))
|
||||||
.hget("hash key 2", "key 2")
|
.hget('hash key 2', 'key 2')
|
||||||
.exec(function (err, reply) {
|
.exec(function (err, reply) {
|
||||||
assert.strictEqual(true, Array.isArray(reply));
|
assert.strictEqual(true, Array.isArray(reply));
|
||||||
assert.strictEqual(4, reply.length);
|
assert.strictEqual(4, reply.length);
|
||||||
assert.strictEqual("val 1", reply[0]);
|
assert.strictEqual('val 1', reply[0]);
|
||||||
assert.strictEqual(true, Buffer.isBuffer(reply[1]));
|
assert.strictEqual(true, Buffer.isBuffer(reply[1]));
|
||||||
assert.strictEqual("<Buffer 76 61 6c 20 31>", reply[1].inspect());
|
assert.strictEqual('<Buffer 76 61 6c 20 31>', reply[1].inspect());
|
||||||
assert.strictEqual(true, Buffer.isBuffer(reply[2]));
|
assert.strictEqual(true, Buffer.isBuffer(reply[2]));
|
||||||
assert.strictEqual("<Buffer 76 61 6c 20 32>", reply[2].inspect());
|
assert.strictEqual('<Buffer 76 61 6c 20 32>', reply[2].inspect());
|
||||||
assert.strictEqual("val 2", reply[3]);
|
assert.strictEqual('val 2', reply[3]);
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -86,19 +86,19 @@ describe("detect_buffers", function () {
|
|||||||
describe('batch.hget', function () {
|
describe('batch.hget', function () {
|
||||||
it('can interleave string and buffer results', function (done) {
|
it('can interleave string and buffer results', function (done) {
|
||||||
client.batch()
|
client.batch()
|
||||||
.hget("hash key 2", "key 1")
|
.hget('hash key 2', 'key 1')
|
||||||
.hget(new Buffer("hash key 2"), "key 1")
|
.hget(new Buffer('hash key 2'), 'key 1')
|
||||||
.hget("hash key 2", new Buffer("key 2"))
|
.hget('hash key 2', new Buffer('key 2'))
|
||||||
.hget("hash key 2", "key 2")
|
.hget('hash key 2', 'key 2')
|
||||||
.exec(function (err, reply) {
|
.exec(function (err, reply) {
|
||||||
assert.strictEqual(true, Array.isArray(reply));
|
assert.strictEqual(true, Array.isArray(reply));
|
||||||
assert.strictEqual(4, reply.length);
|
assert.strictEqual(4, reply.length);
|
||||||
assert.strictEqual("val 1", reply[0]);
|
assert.strictEqual('val 1', reply[0]);
|
||||||
assert.strictEqual(true, Buffer.isBuffer(reply[1]));
|
assert.strictEqual(true, Buffer.isBuffer(reply[1]));
|
||||||
assert.strictEqual("<Buffer 76 61 6c 20 31>", reply[1].inspect());
|
assert.strictEqual('<Buffer 76 61 6c 20 31>', reply[1].inspect());
|
||||||
assert.strictEqual(true, Buffer.isBuffer(reply[2]));
|
assert.strictEqual(true, Buffer.isBuffer(reply[2]));
|
||||||
assert.strictEqual("<Buffer 76 61 6c 20 32>", reply[2].inspect());
|
assert.strictEqual('<Buffer 76 61 6c 20 32>', reply[2].inspect());
|
||||||
assert.strictEqual("val 2", reply[3]);
|
assert.strictEqual('val 2', reply[3]);
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -107,28 +107,28 @@ describe("detect_buffers", function () {
|
|||||||
describe('hmget', function () {
|
describe('hmget', function () {
|
||||||
describe('first argument is a string', function () {
|
describe('first argument is a string', function () {
|
||||||
it('returns strings for keys requested', function (done) {
|
it('returns strings for keys requested', function (done) {
|
||||||
client.hmget("hash key 2", "key 1", "key 2", function (err, reply) {
|
client.hmget('hash key 2', 'key 1', 'key 2', function (err, reply) {
|
||||||
assert.strictEqual(true, Array.isArray(reply));
|
assert.strictEqual(true, Array.isArray(reply));
|
||||||
assert.strictEqual(2, reply.length);
|
assert.strictEqual(2, reply.length);
|
||||||
assert.strictEqual("val 1", reply[0]);
|
assert.strictEqual('val 1', reply[0]);
|
||||||
assert.strictEqual("val 2", reply[1]);
|
assert.strictEqual('val 2', reply[1]);
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns strings for keys requested in transaction', function (done) {
|
it('returns strings for keys requested in transaction', function (done) {
|
||||||
client.multi().hmget("hash key 2", "key 1", "key 2").exec(function (err, reply) {
|
client.multi().hmget('hash key 2', 'key 1', 'key 2').exec(function (err, reply) {
|
||||||
assert.strictEqual(true, Array.isArray(reply));
|
assert.strictEqual(true, Array.isArray(reply));
|
||||||
assert.strictEqual(1, reply.length);
|
assert.strictEqual(1, reply.length);
|
||||||
assert.strictEqual(2, reply[0].length);
|
assert.strictEqual(2, reply[0].length);
|
||||||
assert.strictEqual("val 1", reply[0][0]);
|
assert.strictEqual('val 1', reply[0][0]);
|
||||||
assert.strictEqual("val 2", reply[0][1]);
|
assert.strictEqual('val 2', reply[0][1]);
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles array of strings with undefined values (repro #344)', function (done) {
|
it('handles array of strings with undefined values (repro #344)', function (done) {
|
||||||
client.hmget("hash key 2", "key 3", "key 4", function(err, reply) {
|
client.hmget('hash key 2', 'key 3', 'key 4', function (err, reply) {
|
||||||
assert.strictEqual(true, Array.isArray(reply));
|
assert.strictEqual(true, Array.isArray(reply));
|
||||||
assert.strictEqual(2, reply.length);
|
assert.strictEqual(2, reply.length);
|
||||||
assert.equal(null, reply[0]);
|
assert.equal(null, reply[0]);
|
||||||
@@ -138,7 +138,7 @@ describe("detect_buffers", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('handles array of strings with undefined values in transaction (repro #344)', function (done) {
|
it('handles array of strings with undefined values in transaction (repro #344)', function (done) {
|
||||||
client.multi().hmget("hash key 2", "key 3", "key 4").exec(function(err, reply) {
|
client.multi().hmget('hash key 2', 'key 3', 'key 4').exec(function (err, reply) {
|
||||||
assert.strictEqual(true, Array.isArray(reply));
|
assert.strictEqual(true, Array.isArray(reply));
|
||||||
assert.strictEqual(1, reply.length);
|
assert.strictEqual(1, reply.length);
|
||||||
assert.strictEqual(2, reply[0].length);
|
assert.strictEqual(2, reply[0].length);
|
||||||
@@ -151,39 +151,39 @@ describe("detect_buffers", function () {
|
|||||||
|
|
||||||
describe('first argument is a buffer', function () {
|
describe('first argument is a buffer', function () {
|
||||||
it('returns buffers for keys requested', function (done) {
|
it('returns buffers for keys requested', function (done) {
|
||||||
client.hmget(new Buffer("hash key 2"), "key 1", "key 2", function (err, reply) {
|
client.hmget(new Buffer('hash key 2'), 'key 1', 'key 2', function (err, reply) {
|
||||||
assert.strictEqual(true, Array.isArray(reply));
|
assert.strictEqual(true, Array.isArray(reply));
|
||||||
assert.strictEqual(2, reply.length);
|
assert.strictEqual(2, reply.length);
|
||||||
assert.strictEqual(true, Buffer.isBuffer(reply[0]));
|
assert.strictEqual(true, Buffer.isBuffer(reply[0]));
|
||||||
assert.strictEqual(true, Buffer.isBuffer(reply[1]));
|
assert.strictEqual(true, Buffer.isBuffer(reply[1]));
|
||||||
assert.strictEqual("<Buffer 76 61 6c 20 31>", reply[0].inspect());
|
assert.strictEqual('<Buffer 76 61 6c 20 31>', reply[0].inspect());
|
||||||
assert.strictEqual("<Buffer 76 61 6c 20 32>", reply[1].inspect());
|
assert.strictEqual('<Buffer 76 61 6c 20 32>', reply[1].inspect());
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns buffers for keys requested in transaction", function (done) {
|
it('returns buffers for keys requested in transaction', function (done) {
|
||||||
client.multi().hmget(new Buffer("hash key 2"), "key 1", "key 2").exec(function (err, reply) {
|
client.multi().hmget(new Buffer('hash key 2'), 'key 1', 'key 2').exec(function (err, reply) {
|
||||||
assert.strictEqual(true, Array.isArray(reply));
|
assert.strictEqual(true, Array.isArray(reply));
|
||||||
assert.strictEqual(1, reply.length);
|
assert.strictEqual(1, reply.length);
|
||||||
assert.strictEqual(2, reply[0].length);
|
assert.strictEqual(2, reply[0].length);
|
||||||
assert.strictEqual(true, Buffer.isBuffer(reply[0][0]));
|
assert.strictEqual(true, Buffer.isBuffer(reply[0][0]));
|
||||||
assert.strictEqual(true, Buffer.isBuffer(reply[0][1]));
|
assert.strictEqual(true, Buffer.isBuffer(reply[0][1]));
|
||||||
assert.strictEqual("<Buffer 76 61 6c 20 31>", reply[0][0].inspect());
|
assert.strictEqual('<Buffer 76 61 6c 20 31>', reply[0][0].inspect());
|
||||||
assert.strictEqual("<Buffer 76 61 6c 20 32>", reply[0][1].inspect());
|
assert.strictEqual('<Buffer 76 61 6c 20 32>', reply[0][1].inspect());
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns buffers for keys requested in .batch", function (done) {
|
it('returns buffers for keys requested in .batch', function (done) {
|
||||||
client.batch().hmget(new Buffer("hash key 2"), "key 1", "key 2").exec(function (err, reply) {
|
client.batch().hmget(new Buffer('hash key 2'), 'key 1', 'key 2').exec(function (err, reply) {
|
||||||
assert.strictEqual(true, Array.isArray(reply));
|
assert.strictEqual(true, Array.isArray(reply));
|
||||||
assert.strictEqual(1, reply.length);
|
assert.strictEqual(1, reply.length);
|
||||||
assert.strictEqual(2, reply[0].length);
|
assert.strictEqual(2, reply[0].length);
|
||||||
assert.strictEqual(true, Buffer.isBuffer(reply[0][0]));
|
assert.strictEqual(true, Buffer.isBuffer(reply[0][0]));
|
||||||
assert.strictEqual(true, Buffer.isBuffer(reply[0][1]));
|
assert.strictEqual(true, Buffer.isBuffer(reply[0][1]));
|
||||||
assert.strictEqual("<Buffer 76 61 6c 20 31>", reply[0][0].inspect());
|
assert.strictEqual('<Buffer 76 61 6c 20 31>', reply[0][0].inspect());
|
||||||
assert.strictEqual("<Buffer 76 61 6c 20 32>", reply[0][1].inspect());
|
assert.strictEqual('<Buffer 76 61 6c 20 32>', reply[0][1].inspect());
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -193,33 +193,33 @@ describe("detect_buffers", function () {
|
|||||||
describe('hgetall', function (done) {
|
describe('hgetall', function (done) {
|
||||||
describe('first argument is a string', function () {
|
describe('first argument is a string', function () {
|
||||||
it('returns string values', function (done) {
|
it('returns string values', function (done) {
|
||||||
client.hgetall("hash key 2", function (err, reply) {
|
client.hgetall('hash key 2', function (err, reply) {
|
||||||
assert.strictEqual("object", typeof reply);
|
assert.strictEqual('object', typeof reply);
|
||||||
assert.strictEqual(2, Object.keys(reply).length);
|
assert.strictEqual(2, Object.keys(reply).length);
|
||||||
assert.strictEqual("val 1", reply["key 1"]);
|
assert.strictEqual('val 1', reply['key 1']);
|
||||||
assert.strictEqual("val 2", reply["key 2"]);
|
assert.strictEqual('val 2', reply['key 2']);
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns string values when executed in transaction', function (done) {
|
it('returns string values when executed in transaction', function (done) {
|
||||||
client.multi().hgetall("hash key 2").exec(function (err, reply) {
|
client.multi().hgetall('hash key 2').exec(function (err, reply) {
|
||||||
assert.strictEqual(1, reply.length);
|
assert.strictEqual(1, reply.length);
|
||||||
assert.strictEqual("object", typeof reply[0]);
|
assert.strictEqual('object', typeof reply[0]);
|
||||||
assert.strictEqual(2, Object.keys(reply[0]).length);
|
assert.strictEqual(2, Object.keys(reply[0]).length);
|
||||||
assert.strictEqual("val 1", reply[0]["key 1"]);
|
assert.strictEqual('val 1', reply[0]['key 1']);
|
||||||
assert.strictEqual("val 2", reply[0]["key 2"]);
|
assert.strictEqual('val 2', reply[0]['key 2']);
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns string values when executed in .batch', function (done) {
|
it('returns string values when executed in .batch', function (done) {
|
||||||
client.batch().hgetall("hash key 2").exec(function (err, reply) {
|
client.batch().hgetall('hash key 2').exec(function (err, reply) {
|
||||||
assert.strictEqual(1, reply.length);
|
assert.strictEqual(1, reply.length);
|
||||||
assert.strictEqual("object", typeof reply[0]);
|
assert.strictEqual('object', typeof reply[0]);
|
||||||
assert.strictEqual(2, Object.keys(reply[0]).length);
|
assert.strictEqual(2, Object.keys(reply[0]).length);
|
||||||
assert.strictEqual("val 1", reply[0]["key 1"]);
|
assert.strictEqual('val 1', reply[0]['key 1']);
|
||||||
assert.strictEqual("val 2", reply[0]["key 2"]);
|
assert.strictEqual('val 2', reply[0]['key 2']);
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -227,40 +227,40 @@ describe("detect_buffers", function () {
|
|||||||
|
|
||||||
describe('first argument is a buffer', function () {
|
describe('first argument is a buffer', function () {
|
||||||
it('returns buffer values', function (done) {
|
it('returns buffer values', function (done) {
|
||||||
client.hgetall(new Buffer("hash key 2"), function (err, reply) {
|
client.hgetall(new Buffer('hash key 2'), function (err, reply) {
|
||||||
assert.strictEqual(null, err);
|
assert.strictEqual(null, err);
|
||||||
assert.strictEqual("object", typeof reply);
|
assert.strictEqual('object', typeof reply);
|
||||||
assert.strictEqual(2, Object.keys(reply).length);
|
assert.strictEqual(2, Object.keys(reply).length);
|
||||||
assert.strictEqual(true, Buffer.isBuffer(reply["key 1"]));
|
assert.strictEqual(true, Buffer.isBuffer(reply['key 1']));
|
||||||
assert.strictEqual(true, Buffer.isBuffer(reply["key 2"]));
|
assert.strictEqual(true, Buffer.isBuffer(reply['key 2']));
|
||||||
assert.strictEqual("<Buffer 76 61 6c 20 31>", reply["key 1"].inspect());
|
assert.strictEqual('<Buffer 76 61 6c 20 31>', reply['key 1'].inspect());
|
||||||
assert.strictEqual("<Buffer 76 61 6c 20 32>", reply["key 2"].inspect());
|
assert.strictEqual('<Buffer 76 61 6c 20 32>', reply['key 2'].inspect());
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns buffer values when executed in transaction', function (done) {
|
it('returns buffer values when executed in transaction', function (done) {
|
||||||
client.multi().hgetall(new Buffer("hash key 2")).exec(function (err, reply) {
|
client.multi().hgetall(new Buffer('hash key 2')).exec(function (err, reply) {
|
||||||
assert.strictEqual(1, reply.length);
|
assert.strictEqual(1, reply.length);
|
||||||
assert.strictEqual("object", typeof reply[0]);
|
assert.strictEqual('object', typeof reply[0]);
|
||||||
assert.strictEqual(2, Object.keys(reply[0]).length);
|
assert.strictEqual(2, Object.keys(reply[0]).length);
|
||||||
assert.strictEqual(true, Buffer.isBuffer(reply[0]["key 1"]));
|
assert.strictEqual(true, Buffer.isBuffer(reply[0]['key 1']));
|
||||||
assert.strictEqual(true, Buffer.isBuffer(reply[0]["key 2"]));
|
assert.strictEqual(true, Buffer.isBuffer(reply[0]['key 2']));
|
||||||
assert.strictEqual("<Buffer 76 61 6c 20 31>", reply[0]["key 1"].inspect());
|
assert.strictEqual('<Buffer 76 61 6c 20 31>', reply[0]['key 1'].inspect());
|
||||||
assert.strictEqual("<Buffer 76 61 6c 20 32>", reply[0]["key 2"].inspect());
|
assert.strictEqual('<Buffer 76 61 6c 20 32>', reply[0]['key 2'].inspect());
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns buffer values when executed in .batch', function (done) {
|
it('returns buffer values when executed in .batch', function (done) {
|
||||||
client.batch().hgetall(new Buffer("hash key 2")).exec(function (err, reply) {
|
client.batch().hgetall(new Buffer('hash key 2')).exec(function (err, reply) {
|
||||||
assert.strictEqual(1, reply.length);
|
assert.strictEqual(1, reply.length);
|
||||||
assert.strictEqual("object", typeof reply[0]);
|
assert.strictEqual('object', typeof reply[0]);
|
||||||
assert.strictEqual(2, Object.keys(reply[0]).length);
|
assert.strictEqual(2, Object.keys(reply[0]).length);
|
||||||
assert.strictEqual(true, Buffer.isBuffer(reply[0]["key 1"]));
|
assert.strictEqual(true, Buffer.isBuffer(reply[0]['key 1']));
|
||||||
assert.strictEqual(true, Buffer.isBuffer(reply[0]["key 2"]));
|
assert.strictEqual(true, Buffer.isBuffer(reply[0]['key 2']));
|
||||||
assert.strictEqual("<Buffer 76 61 6c 20 31>", reply[0]["key 1"].inspect());
|
assert.strictEqual('<Buffer 76 61 6c 20 31>', reply[0]['key 1'].inspect());
|
||||||
assert.strictEqual("<Buffer 76 61 6c 20 32>", reply[0]["key 2"].inspect());
|
assert.strictEqual('<Buffer 76 61 6c 20 32>', reply[0]['key 2'].inspect());
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -1,10 +1,10 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require("assert");
|
var assert = require('assert');
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var config = require("./lib/config");
|
var config = require('./lib/config');
|
||||||
var RedisProcess = require("./lib/redis-process");
|
var RedisProcess = require('./lib/redis-process');
|
||||||
var StunnelProcess = require("./lib/stunnel-process");
|
var StunnelProcess = require('./lib/stunnel-process');
|
||||||
var rp;
|
var rp;
|
||||||
var stunnel_process;
|
var stunnel_process;
|
||||||
|
|
||||||
@@ -52,59 +52,59 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
isNumber: function (expected, done) {
|
isNumber: function (expected, done) {
|
||||||
return function (err, results) {
|
return function (err, results) {
|
||||||
assert.strictEqual(null, err, "expected " + expected + ", got error: " + err);
|
assert.strictEqual(null, err, 'expected ' + expected + ', got error: ' + err);
|
||||||
assert.strictEqual(expected, results, expected + " !== " + results);
|
assert.strictEqual(expected, results, expected + ' !== ' + results);
|
||||||
assert.strictEqual(typeof results, "number", "expected a number, got " + typeof results);
|
assert.strictEqual(typeof results, 'number', 'expected a number, got ' + typeof results);
|
||||||
if (done) return done();
|
if (done) done();
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
isString: function (str, done) {
|
isString: function (str, done) {
|
||||||
return function (err, results) {
|
return function (err, results) {
|
||||||
assert.strictEqual(null, err, "expected string '" + str + "', got error: " + err);
|
assert.strictEqual(null, err, "expected string '" + str + "', got error: " + err);
|
||||||
assert.equal(str, results, str + " does not match " + results);
|
assert.equal(str, results, str + ' does not match ' + results);
|
||||||
if (done) return done();
|
if (done) done();
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
isNull: function (done) {
|
isNull: function (done) {
|
||||||
return function (err, results) {
|
return function (err, results) {
|
||||||
assert.strictEqual(null, err, "expected null, got error: " + err);
|
assert.strictEqual(null, err, 'expected null, got error: ' + err);
|
||||||
assert.strictEqual(null, results, results + " is not null");
|
assert.strictEqual(null, results, results + ' is not null');
|
||||||
if (done) return done();
|
if (done) done();
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
isError: function (done) {
|
isError: function (done) {
|
||||||
return function (err, results) {
|
return function (err, results) {
|
||||||
assert(err instanceof Error, "err is not instance of 'Error', but an error is expected here.");
|
assert(err instanceof Error, "err is not instance of 'Error', but an error is expected here.");
|
||||||
if (done) return done();
|
if (done) done();
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
isNotError: function (done) {
|
isNotError: function (done) {
|
||||||
return function (err, results) {
|
return function (err, results) {
|
||||||
assert.strictEqual(err, null, "expected success, got an error: " + err);
|
assert.strictEqual(err, null, 'expected success, got an error: ' + err);
|
||||||
if (done) return done();
|
if (done) done();
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
isType: {
|
isType: {
|
||||||
number: function (done) {
|
number: function (done) {
|
||||||
return function (err, results) {
|
return function (err, results) {
|
||||||
assert.strictEqual(null, err, "expected any number, got error: " + err);
|
assert.strictEqual(null, err, 'expected any number, got error: ' + err);
|
||||||
assert.strictEqual(typeof results, "number", results + " is not a number");
|
assert.strictEqual(typeof results, 'number', results + ' is not a number');
|
||||||
if (done) return done();
|
if (done) done();
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
positiveNumber: function (done) {
|
positiveNumber: function (done) {
|
||||||
return function (err, results) {
|
return function (err, results) {
|
||||||
assert.strictEqual(null, err, "expected positive number, got error: " + err);
|
assert.strictEqual(null, err, 'expected positive number, got error: ' + err);
|
||||||
assert.strictEqual(true, (results > 0), results + " is not a positive number");
|
assert.strictEqual(true, (results > 0), results + ' is not a positive number');
|
||||||
if (done) return done();
|
if (done) done();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
match: function (pattern, done) {
|
match: function (pattern, done) {
|
||||||
return function (err, results) {
|
return function (err, results) {
|
||||||
assert.strictEqual(null, err, "expected " + pattern.toString() + ", got error: " + err);
|
assert.strictEqual(null, err, 'expected ' + pattern.toString() + ', got error: ' + err);
|
||||||
assert(pattern.test(results), "expected string '" + results + "' to match " + pattern.toString());
|
assert(pattern.test(results), "expected string '" + results + "' to match " + pattern.toString());
|
||||||
if (done) return done();
|
if (done) done();
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
serverVersionAtLeast: function (connection, desired_version) {
|
serverVersionAtLeast: function (connection, desired_version) {
|
||||||
@@ -131,7 +131,7 @@ module.exports = {
|
|||||||
try {
|
try {
|
||||||
require('hiredis');
|
require('hiredis');
|
||||||
parsers.push('hiredis');
|
parsers.push('hiredis');
|
||||||
} catch (e) {}
|
} catch (e) {/* ignore eslint */}
|
||||||
if (process.platform !== 'win32') {
|
if (process.platform !== 'win32') {
|
||||||
protocols.push('IPv6', '/tmp/redis.sock');
|
protocols.push('IPv6', '/tmp/redis.sock');
|
||||||
}
|
}
|
||||||
|
@@ -13,8 +13,8 @@ var config = {
|
|||||||
redis: redis,
|
redis: redis,
|
||||||
PORT: 6379,
|
PORT: 6379,
|
||||||
HOST: {
|
HOST: {
|
||||||
IPv4: "127.0.0.1",
|
IPv4: '127.0.0.1',
|
||||||
IPv6: "::1"
|
IPv6: '::1'
|
||||||
},
|
},
|
||||||
configureClient: function (parser, ip, opts) {
|
configureClient: function (parser, ip, opts) {
|
||||||
var args = [];
|
var args = [];
|
||||||
|
@@ -52,11 +52,11 @@ module.exports = {
|
|||||||
var spawnFailed = false;
|
var spawnFailed = false;
|
||||||
// spawn redis with our testing configuration.
|
// spawn redis with our testing configuration.
|
||||||
var confFile = conf || path.resolve(__dirname, '../conf/redis.conf');
|
var confFile = conf || path.resolve(__dirname, '../conf/redis.conf');
|
||||||
var rp = spawn("redis-server", [confFile], {});
|
var rp = spawn('redis-server', [confFile], {});
|
||||||
|
|
||||||
// capture a failure booting redis, and give
|
// capture a failure booting redis, and give
|
||||||
// the user running the test some directions.
|
// the user running the test some directions.
|
||||||
rp.once("exit", function (code) {
|
rp.once('exit', function (code) {
|
||||||
if (code !== 0) spawnFailed = true;
|
if (code !== 0) spawnFailed = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -71,7 +71,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
stop: function (done) {
|
stop: function (done) {
|
||||||
if (spawnFailed) return done();
|
if (spawnFailed) return done();
|
||||||
rp.once("exit", function (code) {
|
rp.once('exit', function (code) {
|
||||||
var error = null;
|
var error = null;
|
||||||
if (code !== null && code !== 0) {
|
if (code !== null && code !== 0) {
|
||||||
error = new Error('Redis shutdown failed with code ' + code);
|
error = new Error('Redis shutdown failed with code ' + code);
|
||||||
@@ -80,7 +80,7 @@ module.exports = {
|
|||||||
return done(error);
|
return done(error);
|
||||||
}, port);
|
}, port);
|
||||||
});
|
});
|
||||||
rp.kill("SIGTERM");
|
rp.kill('SIGTERM');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, port);
|
}, port);
|
||||||
|
@@ -52,7 +52,7 @@ function StunnelProcess(conf_dir) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// wait to stunnel to start
|
// wait to stunnel to start
|
||||||
stunnel.stderr.on("data", function(data) {
|
stunnel.stderr.on('data', function (data) {
|
||||||
if (data.toString().match(/Service.+redis.+bound/)) {
|
if (data.toString().match(/Service.+redis.+bound/)) {
|
||||||
clearTimeout(this.timer);
|
clearTimeout(this.timer);
|
||||||
self.emit('started');
|
self.emit('started');
|
||||||
|
@@ -3,7 +3,7 @@
|
|||||||
// as soon as there are no outstanding commands.
|
// as soon as there are no outstanding commands.
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var redis = require("../../index");
|
var redis = require('../../index');
|
||||||
var HOST = process.argv[2] || '127.0.0.1';
|
var HOST = process.argv[2] || '127.0.0.1';
|
||||||
var PORT = process.argv[3];
|
var PORT = process.argv[3];
|
||||||
var args = PORT ? [PORT, HOST] : [HOST];
|
var args = PORT ? [PORT, HOST] : [HOST];
|
||||||
|
@@ -1,11 +1,10 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
var config = require("./lib/config");
|
var config = require('./lib/config');
|
||||||
var helper = require('./helper');
|
var helper = require('./helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
var zlib = require('zlib');
|
var zlib = require('zlib');
|
||||||
var uuid = require('uuid');
|
|
||||||
var client;
|
var client;
|
||||||
|
|
||||||
describe("The 'multi' method", function () {
|
describe("The 'multi' method", function () {
|
||||||
@@ -23,14 +22,14 @@ describe("The 'multi' method", function () {
|
|||||||
|
|
||||||
// Some random object created from http://beta.json-generator.com/
|
// Some random object created from http://beta.json-generator.com/
|
||||||
var test_obj = {
|
var test_obj = {
|
||||||
"_id": "5642c4c33d4667c4a1fefd99","index": 0, "guid": "5baf1f1c-7621-41e7-ae7a-f8c6f3199b0f", "isActive": true,
|
'_id': '5642c4c33d4667c4a1fefd99', 'index': 0, 'guid': '5baf1f1c-7621-41e7-ae7a-f8c6f3199b0f', 'isActive': true,
|
||||||
"balance": "$1,028.63", "picture": "http://placehold.it/32x32", "age": 31, "eyeColor": "green", "name": {"first": "Shana", "last": "Long"},
|
'balance': '$1,028.63', 'picture': 'http://placehold.it/32x32', 'age': 31, 'eyeColor': 'green', 'name': {'first': 'Shana', 'last': 'Long'},
|
||||||
"company": "MANGLO", "email": "shana.long@manglo.us", "phone": "+1 (926) 405-3105", "address": "747 Dank Court, Norfolk, Ohio, 1112",
|
'company': 'MANGLO', 'email': 'shana.long@manglo.us', 'phone': '+1 (926) 405-3105', 'address': '747 Dank Court, Norfolk, Ohio, 1112',
|
||||||
"about": "Eu pariatur in nisi occaecat enim qui consequat nostrud cupidatat id. " +
|
'about': 'Eu pariatur in nisi occaecat enim qui consequat nostrud cupidatat id. ' +
|
||||||
"Commodo commodo dolore esse irure minim quis deserunt anim laborum aute deserunt et est. Quis nisi laborum deserunt nisi quis.",
|
'Commodo commodo dolore esse irure minim quis deserunt anim laborum aute deserunt et est. Quis nisi laborum deserunt nisi quis.',
|
||||||
"registered": "Friday, April 18, 2014 9:56 AM", "latitude": "74.566613", "longitude": "-11.660432", "tags": [7, "excepteur"],
|
'registered': 'Friday, April 18, 2014 9:56 AM', 'latitude': '74.566613', 'longitude': '-11.660432', 'tags': [7, 'excepteur'],
|
||||||
"range": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], "friends": [3, {"id": 1, "name": "Schultz Dyer"}],
|
'range': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 'friends': [3, {'id': 1, 'name': 'Schultz Dyer'}],
|
||||||
"greeting": "Hello, Shana! You have 5 unread messages.", "favoriteFruit": "strawberry"
|
'greeting': 'Hello, Shana! You have 5 unread messages.', 'favoriteFruit': 'strawberry'
|
||||||
};
|
};
|
||||||
|
|
||||||
function run () {
|
function run () {
|
||||||
@@ -39,7 +38,8 @@ describe("The 'multi' method", function () {
|
|||||||
}
|
}
|
||||||
// To demonstrate a big payload for hash set field values, let's create a big array
|
// To demonstrate a big payload for hash set field values, let's create a big array
|
||||||
var test_arr = [];
|
var test_arr = [];
|
||||||
for (var i = 0; i < 80; i++) {
|
var i = 0;
|
||||||
|
for (; i < 80; i++) {
|
||||||
var new_obj = JSON.parse(JSON.stringify(test_obj));
|
var new_obj = JSON.parse(JSON.stringify(test_obj));
|
||||||
test_arr.push(new_obj);
|
test_arr.push(new_obj);
|
||||||
}
|
}
|
||||||
@@ -94,25 +94,19 @@ describe("The 'multi' 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 () {
|
describe('when not connected', function () {
|
||||||
key = uuid.v4();
|
|
||||||
value = uuid.v4();
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("when not connected", function () {
|
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.quit();
|
client.quit();
|
||||||
});
|
});
|
||||||
client.once('end', done);
|
client.once('end', done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("reports an error", function (done) {
|
it('reports an error', function (done) {
|
||||||
var multi = client.multi();
|
var multi = client.multi();
|
||||||
var notBuffering = multi.exec(function (err, res) {
|
var notBuffering = multi.exec(function (err, res) {
|
||||||
assert(err.message.match(/The connection has already been closed/));
|
assert(err.message.match(/The connection has already been closed/));
|
||||||
@@ -121,33 +115,33 @@ describe("The 'multi' method", function () {
|
|||||||
assert.strictEqual(notBuffering, false);
|
assert.strictEqual(notBuffering, false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("reports an error if promisified", function () {
|
it('reports an error if promisified', function () {
|
||||||
return client.multi().execAsync().catch(function (err) {
|
return client.multi().execAsync().catch(function (err) {
|
||||||
assert(err.message.match(/The connection has already been closed/));
|
assert(err.message.match(/The connection has already been closed/));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when connected", function () {
|
describe('when connected', function () {
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("connect", done);
|
client.once('connect', done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("executes a pipelined multi properly in combination with the offline queue", function (done) {
|
it('executes a pipelined multi properly in combination with the offline queue', function (done) {
|
||||||
var multi1 = client.multi();
|
var multi1 = client.multi();
|
||||||
multi1.set("m1", "123");
|
multi1.set('m1', '123');
|
||||||
multi1.get('m1');
|
multi1.get('m1');
|
||||||
multi1.exec(done);
|
multi1.exec(done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("executes a pipelined multi properly after a reconnect in combination with the offline queue", function (done) {
|
it('executes a pipelined multi properly after a reconnect in combination with the offline queue', function (done) {
|
||||||
client.once('ready', function () {
|
client.once('ready', function () {
|
||||||
client.stream.destroy();
|
client.stream.destroy();
|
||||||
var called = false;
|
var called = false;
|
||||||
var multi1 = client.multi();
|
var multi1 = client.multi();
|
||||||
multi1.set("m1", "123");
|
multi1.set('m1', '123');
|
||||||
multi1.get('m1');
|
multi1.get('m1');
|
||||||
multi1.exec(function (err, res) {
|
multi1.exec(function (err, res) {
|
||||||
assert(!err);
|
assert(!err);
|
||||||
@@ -155,7 +149,7 @@ describe("The 'multi' method", function () {
|
|||||||
});
|
});
|
||||||
client.once('ready', function () {
|
client.once('ready', function () {
|
||||||
var multi1 = client.multi();
|
var multi1 = client.multi();
|
||||||
multi1.set("m2", "456");
|
multi1.set('m2', '456');
|
||||||
multi1.get('m2');
|
multi1.get('m2');
|
||||||
multi1.exec(function (err, res) {
|
multi1.exec(function (err, res) {
|
||||||
assert(called);
|
assert(called);
|
||||||
@@ -168,9 +162,9 @@ describe("The 'multi' method", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when connection is broken", function () {
|
describe('when connection is broken', function () {
|
||||||
|
|
||||||
it("return an error even if connection is in broken mode if callback is present", function (done) {
|
it('return an error even if connection is in broken mode if callback is present', function (done) {
|
||||||
client = redis.createClient({
|
client = redis.createClient({
|
||||||
host: 'somewhere',
|
host: 'somewhere',
|
||||||
port: 6379,
|
port: 6379,
|
||||||
@@ -189,7 +183,7 @@ describe("The 'multi' method", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not emit an error twice if connection is in broken mode with no callback", function (done) {
|
it('does not emit an error twice if connection is in broken mode with no callback', function (done) {
|
||||||
client = redis.createClient({
|
client = redis.createClient({
|
||||||
host: 'somewhere',
|
host: 'somewhere',
|
||||||
port: 6379,
|
port: 6379,
|
||||||
@@ -207,18 +201,18 @@ describe("The 'multi' method", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when ready", function () {
|
describe('when ready', function () {
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("ready", function () {
|
client.once('ready', function () {
|
||||||
client.flushdb(function (err) {
|
client.flushdb(function (err) {
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns an empty result array", function (done) {
|
it('returns an empty result array', function (done) {
|
||||||
var multi = client.multi();
|
var multi = client.multi();
|
||||||
var notBuffering = multi.exec(function (err, res) {
|
var notBuffering = multi.exec(function (err, res) {
|
||||||
assert.strictEqual(err, null);
|
assert.strictEqual(err, null);
|
||||||
@@ -228,21 +222,21 @@ describe("The 'multi' method", function () {
|
|||||||
assert.strictEqual(notBuffering, true);
|
assert.strictEqual(notBuffering, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("runs normal calls in-between multis", function (done) {
|
it('runs normal calls in-between multis', function (done) {
|
||||||
var multi1 = client.multi();
|
var multi1 = client.multi();
|
||||||
multi1.set("m1", "123");
|
multi1.set('m1', '123');
|
||||||
client.set('m2', '456', done);
|
client.set('m2', '456', done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("runs simultaneous multis with the same client", function (done) {
|
it('runs simultaneous multis with the same client', function (done) {
|
||||||
var end = helper.callFuncAfter(done, 2);
|
var end = helper.callFuncAfter(done, 2);
|
||||||
|
|
||||||
var multi1 = client.multi();
|
var multi1 = client.multi();
|
||||||
multi1.set("m1", "123");
|
multi1.set('m1', '123');
|
||||||
multi1.get('m1');
|
multi1.get('m1');
|
||||||
|
|
||||||
var multi2 = client.multi();
|
var multi2 = client.multi();
|
||||||
multi2.set("m2", "456");
|
multi2.set('m2', '456');
|
||||||
multi2.get('m2');
|
multi2.get('m2');
|
||||||
|
|
||||||
multi1.exec(end);
|
multi1.exec(end);
|
||||||
@@ -252,13 +246,13 @@ describe("The 'multi' method", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("runs simultaneous multis with the same client version 2", function (done) {
|
it('runs simultaneous multis with the same client version 2', function (done) {
|
||||||
var end = helper.callFuncAfter(done, 2);
|
var end = helper.callFuncAfter(done, 2);
|
||||||
var multi2 = client.multi();
|
var multi2 = client.multi();
|
||||||
var multi1 = client.multi();
|
var multi1 = client.multi();
|
||||||
|
|
||||||
multi2.set("m2", "456");
|
multi2.set('m2', '456');
|
||||||
multi1.set("m1", "123");
|
multi1.set('m1', '123');
|
||||||
multi1.get('m1');
|
multi1.get('m1');
|
||||||
multi2.get('m2');
|
multi2.get('m2');
|
||||||
multi2.ping();
|
multi2.ping();
|
||||||
@@ -274,11 +268,11 @@ describe("The 'multi' method", function () {
|
|||||||
var multi1, multi2;
|
var multi1, multi2;
|
||||||
// Provoke an error at queue time
|
// Provoke an error at queue time
|
||||||
multi1 = client.MULTI();
|
multi1 = client.MULTI();
|
||||||
multi1.mset("multifoo", "10", "multibar", "20", helper.isString("OK"));
|
multi1.mset('multifoo', '10', 'multibar', '20', helper.isString('OK'));
|
||||||
|
|
||||||
multi1.set("foo2", helper.isError());
|
multi1.set('foo2', helper.isError());
|
||||||
multi1.incr("multifoo");
|
multi1.incr('multifoo');
|
||||||
multi1.incr("multibar");
|
multi1.incr('multibar');
|
||||||
multi1.exec(function () {
|
multi1.exec(function () {
|
||||||
// Redis 2.6.5+ will abort transactions with errors
|
// Redis 2.6.5+ will abort transactions with errors
|
||||||
// see: http://redis.io/topics/transactions
|
// see: http://redis.io/topics/transactions
|
||||||
@@ -286,8 +280,8 @@ describe("The 'multi' method", function () {
|
|||||||
var multifoo_expected = 1;
|
var multifoo_expected = 1;
|
||||||
// Confirm that the previous command, while containing an error, still worked.
|
// Confirm that the previous command, while containing an error, still worked.
|
||||||
multi2 = client.multi();
|
multi2 = client.multi();
|
||||||
multi2.incr("multibar", helper.isNumber(multibar_expected));
|
multi2.incr('multibar', helper.isNumber(multibar_expected));
|
||||||
multi2.incr("multifoo", helper.isNumber(multifoo_expected));
|
multi2.incr('multifoo', helper.isNumber(multifoo_expected));
|
||||||
multi2.exec(function (err, replies) {
|
multi2.exec(function (err, replies) {
|
||||||
assert.strictEqual(multibar_expected, replies[0]);
|
assert.strictEqual(multibar_expected, replies[0]);
|
||||||
assert.strictEqual(multifoo_expected, replies[1]);
|
assert.strictEqual(multifoo_expected, replies[1]);
|
||||||
@@ -299,14 +293,14 @@ describe("The 'multi' method", function () {
|
|||||||
it('roles back a transaction when one command in an array of commands fails', function (done) {
|
it('roles back a transaction when one command in an array of commands fails', function (done) {
|
||||||
// test nested multi-bulk replies
|
// test nested multi-bulk replies
|
||||||
client.multi([
|
client.multi([
|
||||||
["mget", "multifoo", "multibar", function (err, res) {
|
['mget', 'multifoo', 'multibar', function (err, res) {
|
||||||
assert.strictEqual(2, res.length);
|
assert.strictEqual(2, res.length);
|
||||||
assert.strictEqual(0, +res[0]);
|
assert.strictEqual(0, +res[0]);
|
||||||
assert.strictEqual(0, +res[1]);
|
assert.strictEqual(0, +res[1]);
|
||||||
}],
|
}],
|
||||||
["set", "foo2", helper.isError()],
|
['set', 'foo2', helper.isError()],
|
||||||
["incr", "multifoo"],
|
['incr', 'multifoo'],
|
||||||
["incr", "multibar"]
|
['incr', 'multibar']
|
||||||
]).exec(function (err, replies) {
|
]).exec(function (err, replies) {
|
||||||
assert.notEqual(err, null);
|
assert.notEqual(err, null);
|
||||||
assert.equal(replies, undefined);
|
assert.equal(replies, undefined);
|
||||||
@@ -315,25 +309,25 @@ describe("The 'multi' method", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('handles multiple operations being applied to a set', function (done) {
|
it('handles multiple operations being applied to a set', function (done) {
|
||||||
client.sadd("some set", "mem 1");
|
client.sadd('some set', 'mem 1');
|
||||||
client.sadd(["some set", "mem 2"]);
|
client.sadd(['some set', 'mem 2']);
|
||||||
client.sadd("some set", "mem 3");
|
client.sadd('some set', 'mem 3');
|
||||||
client.sadd("some set", "mem 4");
|
client.sadd('some set', 'mem 4');
|
||||||
|
|
||||||
// make sure empty mb reply works
|
// make sure empty mb reply works
|
||||||
client.del("some missing set");
|
client.del('some missing set');
|
||||||
client.smembers("some missing set", function (err, reply) {
|
client.smembers('some missing set', function (err, reply) {
|
||||||
// make sure empty mb reply works
|
// make sure empty mb reply works
|
||||||
assert.strictEqual(0, reply.length);
|
assert.strictEqual(0, reply.length);
|
||||||
});
|
});
|
||||||
|
|
||||||
// test nested multi-bulk replies with empty mb elements.
|
// test nested multi-bulk replies with empty mb elements.
|
||||||
client.multi([
|
client.multi([
|
||||||
["smembers", ["some set"]],
|
['smembers', ['some set']],
|
||||||
["del", "some set"],
|
['del', 'some set'],
|
||||||
["smembers", "some set"]
|
['smembers', 'some set']
|
||||||
])
|
])
|
||||||
.scard("some set")
|
.scard('some set')
|
||||||
.exec(function (err, replies) {
|
.exec(function (err, replies) {
|
||||||
assert.strictEqual(4, replies[0].length);
|
assert.strictEqual(4, replies[0].length);
|
||||||
assert.strictEqual(0, replies[2].length);
|
assert.strictEqual(0, replies[2].length);
|
||||||
@@ -343,21 +337,21 @@ describe("The 'multi' method", function () {
|
|||||||
|
|
||||||
it('allows multiple operations to be performed using constructor with all kinds of syntax', function (done) {
|
it('allows multiple operations to be performed using constructor with all kinds of syntax', function (done) {
|
||||||
var now = Date.now();
|
var now = Date.now();
|
||||||
var arr = ["multihmset", "multibar", "multibaz"];
|
var arr = ['multihmset', 'multibar', 'multibaz'];
|
||||||
var arr2 = ['some manner of key', 'otherTypes'];
|
var arr2 = ['some manner of key', 'otherTypes'];
|
||||||
var arr3 = [5768, "multibarx", "multifoox"];
|
var arr3 = [5768, 'multibarx', 'multifoox'];
|
||||||
var arr4 = ["mset", [578, "multibar"], helper.isString('OK')];
|
var arr4 = ['mset', [578, 'multibar'], helper.isString('OK')];
|
||||||
client.multi([
|
client.multi([
|
||||||
arr4,
|
arr4,
|
||||||
[["mset", "multifoo2", "multibar2", "multifoo3", "multibar3"], helper.isString('OK')],
|
[['mset', 'multifoo2', 'multibar2', 'multifoo3', 'multibar3'], helper.isString('OK')],
|
||||||
["hmset", arr],
|
['hmset', arr],
|
||||||
[["hmset", "multihmset2", "multibar2", "multifoo3", "multibar3", "test"], helper.isString('OK')],
|
[['hmset', 'multihmset2', 'multibar2', 'multifoo3', 'multibar3', 'test'], helper.isString('OK')],
|
||||||
["hmset", ["multihmset", "multibar", "multifoo"], helper.isString('OK')],
|
['hmset', ['multihmset', 'multibar', 'multifoo'], helper.isString('OK')],
|
||||||
["hmset", arr3, helper.isString('OK')],
|
['hmset', arr3, helper.isString('OK')],
|
||||||
['hmset', now, {123456789: "abcdefghij", "some manner of key": "a type of value", "otherTypes": 555}],
|
['hmset', now, {123456789: 'abcdefghij', 'some manner of key': 'a type of value', 'otherTypes': 555}],
|
||||||
['hmset', 'key2', {"0123456789": "abcdefghij", "some manner of key": "a type of value", "otherTypes": 999}, helper.isString('OK')],
|
['hmset', 'key2', {'0123456789': 'abcdefghij', 'some manner of key': 'a type of value', 'otherTypes': 999}, helper.isString('OK')],
|
||||||
["HMSET", "multihmset", ["multibar", "multibaz"], undefined], // undefined is used as a explicit not set callback variable
|
['HMSET', 'multihmset', ['multibar', 'multibaz'], undefined], // undefined is used as a explicit not set callback variable
|
||||||
["hmset", "multihmset", ["multibar", "multibaz"], helper.isString('OK')],
|
['hmset', 'multihmset', ['multibar', 'multibaz'], helper.isString('OK')],
|
||||||
])
|
])
|
||||||
.hmget(now, 123456789, 'otherTypes')
|
.hmget(now, 123456789, 'otherTypes')
|
||||||
.hmget('key2', arr2, function noop () {})
|
.hmget('key2', arr2, function noop () {})
|
||||||
@@ -453,8 +447,8 @@ describe("The 'multi' method", function () {
|
|||||||
it('allows an array to be provided indicating multiple operations to perform', function (done) {
|
it('allows an array to be provided indicating multiple operations to perform', function (done) {
|
||||||
// test nested multi-bulk replies with nulls.
|
// test nested multi-bulk replies with nulls.
|
||||||
client.multi([
|
client.multi([
|
||||||
["mget", ["multifoo", "some", "random value", "keys"]],
|
['mget', ['multifoo', 'some', 'random value', 'keys']],
|
||||||
["incr", "multifoo"]
|
['incr', 'multifoo']
|
||||||
])
|
])
|
||||||
.exec(function (err, replies) {
|
.exec(function (err, replies) {
|
||||||
assert.strictEqual(replies.length, 2);
|
assert.strictEqual(replies.length, 2);
|
||||||
@@ -465,101 +459,101 @@ describe("The 'multi' method", function () {
|
|||||||
|
|
||||||
it('allows multiple operations to be performed on a hash', function (done) {
|
it('allows multiple operations to be performed on a hash', function (done) {
|
||||||
client.multi()
|
client.multi()
|
||||||
.hmset("multihash", "a", "foo", "b", 1)
|
.hmset('multihash', 'a', 'foo', 'b', 1)
|
||||||
.hmset("multihash", {
|
.hmset('multihash', {
|
||||||
extra: "fancy",
|
extra: 'fancy',
|
||||||
things: "here"
|
things: 'here'
|
||||||
})
|
})
|
||||||
.hgetall("multihash")
|
.hgetall('multihash')
|
||||||
.exec(function (err, replies) {
|
.exec(function (err, replies) {
|
||||||
assert.strictEqual(null, err);
|
assert.strictEqual(null, err);
|
||||||
assert.equal("OK", replies[0]);
|
assert.equal('OK', replies[0]);
|
||||||
assert.equal(Object.keys(replies[2]).length, 4);
|
assert.equal(Object.keys(replies[2]).length, 4);
|
||||||
assert.equal("foo", replies[2].a);
|
assert.equal('foo', replies[2].a);
|
||||||
assert.equal("1", replies[2].b);
|
assert.equal('1', replies[2].b);
|
||||||
assert.equal("fancy", replies[2].extra);
|
assert.equal('fancy', replies[2].extra);
|
||||||
assert.equal("here", replies[2].things);
|
assert.equal('here', replies[2].things);
|
||||||
return done();
|
return done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('reports EXECABORT exceptions when they occur (while queueing)', function (done) {
|
it('reports EXECABORT exceptions when they occur (while queueing)', function (done) {
|
||||||
client.multi().config("bar").set("foo").set("bar").exec(function (err, reply) {
|
client.multi().config('bar').set('foo').set('bar').exec(function (err, reply) {
|
||||||
assert.equal(err.code, "EXECABORT");
|
assert.equal(err.code, 'EXECABORT');
|
||||||
assert.equal(reply, undefined, "The reply should have been discarded");
|
assert.equal(reply, undefined, 'The reply should have been discarded');
|
||||||
assert(err.message.match(/^EXECABORT/), "Error message should begin with EXECABORT");
|
assert(err.message.match(/^EXECABORT/), 'Error message should begin with EXECABORT');
|
||||||
assert.equal(err.errors.length, 2, "err.errors should have 2 items");
|
assert.equal(err.errors.length, 2, 'err.errors should have 2 items');
|
||||||
assert.strictEqual(err.errors[0].command, 'SET');
|
assert.strictEqual(err.errors[0].command, 'SET');
|
||||||
assert.strictEqual(err.errors[0].code, 'ERR');
|
assert.strictEqual(err.errors[0].code, 'ERR');
|
||||||
assert.strictEqual(err.errors[0].position, 1);
|
assert.strictEqual(err.errors[0].position, 1);
|
||||||
assert(/^ERR/.test(err.errors[0].message), "Actuall error message should begin with ERR");
|
assert(/^ERR/.test(err.errors[0].message), 'Actuall error message should begin with ERR');
|
||||||
return done();
|
return done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('reports multiple exceptions when they occur (while EXEC is running)', function (done) {
|
it('reports multiple exceptions when they occur (while EXEC is running)', function (done) {
|
||||||
client.multi().config("bar").debug("foo").eval("return {err='this is an error'}", 0).exec(function (err, reply) {
|
client.multi().config('bar').debug('foo').eval("return {err='this is an error'}", 0).exec(function (err, reply) {
|
||||||
assert.strictEqual(reply.length, 3);
|
assert.strictEqual(reply.length, 3);
|
||||||
assert.equal(reply[0].code, 'ERR');
|
assert.equal(reply[0].code, 'ERR');
|
||||||
assert.equal(reply[0].command, 'CONFIG');
|
assert.equal(reply[0].command, 'CONFIG');
|
||||||
assert.equal(reply[2].code, undefined);
|
assert.equal(reply[2].code, undefined);
|
||||||
assert.equal(reply[2].command, 'EVAL');
|
assert.equal(reply[2].command, 'EVAL');
|
||||||
assert(/^this is an error/.test(reply[2].message));
|
assert(/^this is an error/.test(reply[2].message));
|
||||||
assert(/^ERR/.test(reply[0].message), "Error message should begin with ERR");
|
assert(/^ERR/.test(reply[0].message), 'Error message should begin with ERR');
|
||||||
assert(/^ERR/.test(reply[1].message), "Error message should begin with ERR");
|
assert(/^ERR/.test(reply[1].message), 'Error message should begin with ERR');
|
||||||
return done();
|
return done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('reports multiple exceptions when they occur (while EXEC is running) promisified', function () {
|
it('reports multiple exceptions when they occur (while EXEC is running) promisified', function () {
|
||||||
return client.multi().config("bar").debug("foo").eval("return {err='this is an error'}", 0).execAsync().then(function (reply) {
|
return client.multi().config('bar').debug('foo').eval("return {err='this is an error'}", 0).execAsync().then(function (reply) {
|
||||||
assert.strictEqual(reply.length, 3);
|
assert.strictEqual(reply.length, 3);
|
||||||
assert.equal(reply[0].code, 'ERR');
|
assert.equal(reply[0].code, 'ERR');
|
||||||
assert.equal(reply[0].command, 'CONFIG');
|
assert.equal(reply[0].command, 'CONFIG');
|
||||||
assert.equal(reply[2].code, undefined);
|
assert.equal(reply[2].code, undefined);
|
||||||
assert.equal(reply[2].command, 'EVAL');
|
assert.equal(reply[2].command, 'EVAL');
|
||||||
assert(/^this is an error/.test(reply[2].message));
|
assert(/^this is an error/.test(reply[2].message));
|
||||||
assert(/^ERR/.test(reply[0].message), "Error message should begin with ERR");
|
assert(/^ERR/.test(reply[0].message), 'Error message should begin with ERR');
|
||||||
assert(/^ERR/.test(reply[1].message), "Error message should begin with ERR");
|
assert(/^ERR/.test(reply[1].message), 'Error message should begin with ERR');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('reports multiple exceptions when they occur (while EXEC is running) and calls cb', function (done) {
|
it('reports multiple exceptions when they occur (while EXEC is running) and calls cb', function (done) {
|
||||||
var multi = client.multi();
|
var multi = client.multi();
|
||||||
multi.config("bar", helper.isError());
|
multi.config('bar', helper.isError());
|
||||||
multi.set('foo', 'bar', helper.isString('OK'));
|
multi.set('foo', 'bar', helper.isString('OK'));
|
||||||
multi.debug("foo").exec(function (err, reply) {
|
multi.debug('foo').exec(function (err, reply) {
|
||||||
assert.strictEqual(reply.length, 3);
|
assert.strictEqual(reply.length, 3);
|
||||||
assert.strictEqual(reply[0].code, 'ERR');
|
assert.strictEqual(reply[0].code, 'ERR');
|
||||||
assert(/^ERR/.test(reply[0].message), "Error message should begin with ERR");
|
assert(/^ERR/.test(reply[0].message), 'Error message should begin with ERR');
|
||||||
assert(/^ERR/.test(reply[2].message), "Error message should begin with ERR");
|
assert(/^ERR/.test(reply[2].message), 'Error message should begin with ERR');
|
||||||
assert.strictEqual(reply[1], "OK");
|
assert.strictEqual(reply[1], 'OK');
|
||||||
client.get('foo', helper.isString('bar', done));
|
client.get('foo', helper.isString('bar', done));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("emits an error if no callback has been provided and execabort error occured", function (done) {
|
it('emits an error if no callback has been provided and execabort error occured', function (done) {
|
||||||
var multi = client.multi();
|
var multi = client.multi();
|
||||||
multi.config("bar");
|
multi.config('bar');
|
||||||
multi.set("foo");
|
multi.set('foo');
|
||||||
multi.exec();
|
multi.exec();
|
||||||
|
|
||||||
client.on('error', function (err) {
|
client.on('error', function (err) {
|
||||||
assert.equal(err.code, "EXECABORT");
|
assert.equal(err.code, 'EXECABORT');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should work without any callback", function (done) {
|
it('should work without any callback', function (done) {
|
||||||
var multi = client.multi();
|
var multi = client.multi();
|
||||||
multi.set("baz", "binary");
|
multi.set('baz', 'binary');
|
||||||
multi.set("foo", "bar");
|
multi.set('foo', 'bar');
|
||||||
multi.exec();
|
multi.exec();
|
||||||
|
|
||||||
client.get('foo', helper.isString('bar', done));
|
client.get('foo', helper.isString('bar', done));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should not use a transaction with exec_atomic if no command is used", function () {
|
it('should not use a transaction with exec_atomic if no command is used', function () {
|
||||||
var multi = client.multi();
|
var multi = client.multi();
|
||||||
var test = false;
|
var test = false;
|
||||||
multi.exec_batch = function () {
|
multi.exec_batch = function () {
|
||||||
@@ -569,30 +563,30 @@ describe("The 'multi' method", function () {
|
|||||||
assert(test);
|
assert(test);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should not use a transaction with exec_atomic if only one command is used", function () {
|
it('should not use a transaction with exec_atomic if only one command is used', function () {
|
||||||
var multi = client.multi();
|
var multi = client.multi();
|
||||||
var test = false;
|
var test = false;
|
||||||
multi.exec_batch = function () {
|
multi.exec_batch = function () {
|
||||||
test = true;
|
test = true;
|
||||||
};
|
};
|
||||||
multi.set("baz", "binary");
|
multi.set('baz', 'binary');
|
||||||
multi.exec_atomic();
|
multi.exec_atomic();
|
||||||
assert(test);
|
assert(test);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should use transaction with exec_atomic and more than one command used", function (done) {
|
it('should use transaction with exec_atomic and more than one command used', function (done) {
|
||||||
var multi = client.multi();
|
var multi = client.multi();
|
||||||
var test = false;
|
var test = false;
|
||||||
multi.exec_batch = function () {
|
multi.exec_batch = function () {
|
||||||
test = true;
|
test = true;
|
||||||
};
|
};
|
||||||
multi.set("baz", "binary");
|
multi.set('baz', 'binary');
|
||||||
multi.get('baz');
|
multi.get('baz');
|
||||||
multi.exec_atomic(done);
|
multi.exec_atomic(done);
|
||||||
assert(!test);
|
assert(!test);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("do not mutate arguments in the multi constructor", function (done) {
|
it('do not mutate arguments in the multi constructor', function (done) {
|
||||||
var input = [['set', 'foo', 'bar'], ['get', 'foo']];
|
var input = [['set', 'foo', 'bar'], ['get', 'foo']];
|
||||||
client.multi(input).exec(function (err, res) {
|
client.multi(input).exec(function (err, res) {
|
||||||
assert.strictEqual(input.length, 2);
|
assert.strictEqual(input.length, 2);
|
||||||
@@ -602,7 +596,7 @@ describe("The 'multi' method", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("works properly after a reconnect. issue #897", function (done) {
|
it('works properly after a reconnect. issue #897', function (done) {
|
||||||
client.stream.destroy();
|
client.stream.destroy();
|
||||||
client.on('error', function (err) {
|
client.on('error', function (err) {
|
||||||
assert.strictEqual(err.code, 'ECONNREFUSED');
|
assert.strictEqual(err.code, 'ECONNREFUSED');
|
||||||
@@ -616,13 +610,13 @@ describe("The 'multi' method", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("emits error once if reconnecting after multi has been executed but not yet returned without callback", function (done) {
|
it('emits error once if reconnecting after multi has been executed but not yet returned without callback', function (done) {
|
||||||
client.on('error', function (err) {
|
client.on('error', function (err) {
|
||||||
assert.strictEqual(err.code, 'UNCERTAIN_STATE');
|
assert.strictEqual(err.code, 'UNCERTAIN_STATE');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
client.multi().set("foo", 'bar').get('foo').exec();
|
client.multi().set('foo', 'bar').get('foo').exec();
|
||||||
// Abort connection before the value returned
|
// Abort connection before the value returned
|
||||||
client.stream.destroy();
|
client.stream.destroy();
|
||||||
});
|
});
|
||||||
|
@@ -1,27 +1,27 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require("assert");
|
var assert = require('assert');
|
||||||
var config = require("./lib/config");
|
var config = require('./lib/config');
|
||||||
var helper = require('./helper');
|
var helper = require('./helper');
|
||||||
var utils = require('../lib/utils');
|
var utils = require('../lib/utils');
|
||||||
var fork = require("child_process").fork;
|
var fork = require('child_process').fork;
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
describe("The node_redis client", function () {
|
describe('The node_redis client', 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 client;
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(function () {
|
||||||
client.end(true);
|
client.end(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when connected", function () {
|
describe('when connected', function () {
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.once("connect", function () {
|
client.once('connect', function () {
|
||||||
client.flushdb(done);
|
client.flushdb(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -107,16 +107,16 @@ describe("The node_redis client", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("send_command", function () {
|
describe('send_command', function () {
|
||||||
|
|
||||||
it("omitting args should be fine in some cases", function (done) {
|
it('omitting args should be fine in some cases', function (done) {
|
||||||
client.send_command("info", undefined, function(err, res) {
|
client.send_command('info', undefined, function (err, res) {
|
||||||
assert(/redis_version/.test(res));
|
assert(/redis_version/.test(res));
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("using another type as cb should just work as if there were no callback parameter", function (done) {
|
it('using another type as cb should just work as if there were no callback parameter', function (done) {
|
||||||
client.send_command('set', ['test', 'bla'], [true]);
|
client.send_command('set', ['test', 'bla'], [true]);
|
||||||
client.get('test', function (err, res) {
|
client.get('test', function (err, res) {
|
||||||
assert.equal(res, 'bla');
|
assert.equal(res, 'bla');
|
||||||
@@ -124,7 +124,7 @@ describe("The node_redis client", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("misusing the function should eventually throw (no command)", function (done) {
|
it('misusing the function should eventually throw (no command)', function (done) {
|
||||||
client.send_command(true, 'info', function (err, res) {
|
client.send_command(true, 'info', function (err, res) {
|
||||||
assert(/ERR Protocol error/.test(err.message));
|
assert(/ERR Protocol error/.test(err.message));
|
||||||
assert.equal(err.command, undefined);
|
assert.equal(err.command, undefined);
|
||||||
@@ -133,7 +133,7 @@ describe("The node_redis client", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("misusing the function should eventually throw (wrong args)", function (done) {
|
it('misusing the function should eventually throw (wrong args)', function (done) {
|
||||||
client.send_command('info', false, function (err, res) {
|
client.send_command('info', false, function (err, res) {
|
||||||
assert.equal(err.message, 'ERR Protocol error: invalid multibulk length');
|
assert.equal(err.message, 'ERR Protocol error: invalid multibulk length');
|
||||||
done();
|
done();
|
||||||
@@ -142,29 +142,29 @@ describe("The node_redis client", function () {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("retry_unfulfilled_commands", function () {
|
describe('retry_unfulfilled_commands', function () {
|
||||||
|
|
||||||
it("should retry all commands instead of returning an error if a command did not yet return after a connection loss", function (done) {
|
it('should retry all commands instead of returning an error if a command did not yet return after a connection loss', function (done) {
|
||||||
var bclient = redis.createClient({
|
var bclient = redis.createClient({
|
||||||
parser: parser,
|
parser: parser,
|
||||||
retry_unfulfilled_commands: true
|
retry_unfulfilled_commands: true
|
||||||
});
|
});
|
||||||
bclient.blpop("blocking list 2", 5, function (err, value) {
|
bclient.blpop('blocking list 2', 5, function (err, value) {
|
||||||
assert.strictEqual(value[0], "blocking list 2");
|
assert.strictEqual(value[0], 'blocking list 2');
|
||||||
assert.strictEqual(value[1], "initial value");
|
assert.strictEqual(value[1], 'initial value');
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
bclient.once('ready', function () {
|
bclient.once('ready', function () {
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
bclient.stream.destroy();
|
bclient.stream.destroy();
|
||||||
client.rpush("blocking list 2", "initial value", helper.isNumber(1));
|
client.rpush('blocking list 2', 'initial value', helper.isNumber(1));
|
||||||
}, 100);
|
}, 100);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe(".end", function () {
|
describe('.end', function () {
|
||||||
|
|
||||||
it('used without flush / flush set to false', function (done) {
|
it('used without flush / flush set to false', function (done) {
|
||||||
var finished = false;
|
var finished = false;
|
||||||
@@ -207,16 +207,16 @@ describe("The node_redis client", function () {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("commands after using .quit should fail", function () {
|
describe('commands after using .quit should fail', function () {
|
||||||
|
|
||||||
it("return an error in the callback", function (done) {
|
it('return an error in the callback', function (done) {
|
||||||
if (helper.redisProcess().spawnFailed()) this.skip();
|
if (helper.redisProcess().spawnFailed()) this.skip();
|
||||||
|
|
||||||
// TODO: Investigate why this test is failing hard and killing mocha if using '/tmp/redis.sock'.
|
// TODO: Investigate why this test is failing hard and killing mocha if using '/tmp/redis.sock'.
|
||||||
// Seems like something is wrong with nyc while passing a socket connection to create client!
|
// Seems like something is wrong with nyc while passing a socket connection to create client!
|
||||||
client = redis.createClient();
|
client = redis.createClient();
|
||||||
client.quit(function () {
|
client.quit(function () {
|
||||||
client.get("foo", function(err, res) {
|
client.get('foo', function (err, res) {
|
||||||
assert(err.message.indexOf('Redis connection gone') !== -1);
|
assert(err.message.indexOf('Redis connection gone') !== -1);
|
||||||
assert.strictEqual(client.offline_queue.length, 0);
|
assert.strictEqual(client.offline_queue.length, 0);
|
||||||
done();
|
done();
|
||||||
@@ -224,12 +224,12 @@ describe("The node_redis client", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("return an error in the callback version two", function (done) {
|
it('return an error in the callback version two', function (done) {
|
||||||
if (helper.redisProcess().spawnFailed()) this.skip();
|
if (helper.redisProcess().spawnFailed()) this.skip();
|
||||||
|
|
||||||
client.quit();
|
client.quit();
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
client.get("foo", function(err, res) {
|
client.get('foo', function (err, res) {
|
||||||
assert.strictEqual(err.message, 'GET can\'t be processed. The connection has already been closed.');
|
assert.strictEqual(err.message, 'GET can\'t be processed. The connection has already been closed.');
|
||||||
assert.strictEqual(err.command, 'GET');
|
assert.strictEqual(err.command, 'GET');
|
||||||
assert.strictEqual(client.offline_queue.length, 0);
|
assert.strictEqual(client.offline_queue.length, 0);
|
||||||
@@ -238,7 +238,7 @@ describe("The node_redis client", function () {
|
|||||||
}, 100);
|
}, 100);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("emit an error", function (done) {
|
it('emit an error', function (done) {
|
||||||
if (helper.redisProcess().spawnFailed()) this.skip();
|
if (helper.redisProcess().spawnFailed()) this.skip();
|
||||||
|
|
||||||
client.quit();
|
client.quit();
|
||||||
@@ -255,47 +255,47 @@ describe("The node_redis client", function () {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when redis closes unexpectedly", function () {
|
describe('when redis closes unexpectedly', function () {
|
||||||
it("reconnects and can retrieve the pre-existing data", function (done) {
|
it('reconnects and can retrieve the pre-existing data', function (done) {
|
||||||
client.on("reconnecting", function on_recon(params) {
|
client.on('reconnecting', function on_recon (params) {
|
||||||
client.on("connect", function on_connect() {
|
client.on('connect', function on_connect () {
|
||||||
var end = helper.callFuncAfter(function () {
|
var end = helper.callFuncAfter(function () {
|
||||||
client.removeListener("connect", on_connect);
|
client.removeListener('connect', on_connect);
|
||||||
client.removeListener("reconnecting", on_recon);
|
client.removeListener('reconnecting', on_recon);
|
||||||
assert.strictEqual(client.server_info.db0.keys, 2);
|
assert.strictEqual(client.server_info.db0.keys, 2);
|
||||||
assert.strictEqual(Object.keys(client.server_info.db0).length, 3);
|
assert.strictEqual(Object.keys(client.server_info.db0).length, 3);
|
||||||
done();
|
done();
|
||||||
}, 4);
|
}, 4);
|
||||||
client.get("recon 1", helper.isString("one", end));
|
client.get('recon 1', helper.isString('one', end));
|
||||||
client.get("recon 1", helper.isString("one", end));
|
client.get('recon 1', helper.isString('one', end));
|
||||||
client.get("recon 2", helper.isString("two", end));
|
client.get('recon 2', helper.isString('two', end));
|
||||||
client.get("recon 2", helper.isString("two", end));
|
client.get('recon 2', helper.isString('two', end));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
client.set("recon 1", "one");
|
client.set('recon 1', 'one');
|
||||||
client.set("recon 2", "two", function (err, res) {
|
client.set('recon 2', 'two', function (err, res) {
|
||||||
// Do not do this in normal programs. This is to simulate the server closing on us.
|
// Do not do this in normal programs. This is to simulate the server closing on us.
|
||||||
// For orderly shutdown in normal programs, do client.quit()
|
// For orderly shutdown in normal programs, do client.quit()
|
||||||
client.stream.destroy();
|
client.stream.destroy();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("reconnects properly when monitoring", function (done) {
|
it('reconnects properly when monitoring', function (done) {
|
||||||
client.on("reconnecting", function on_recon(params) {
|
client.on('reconnecting', function on_recon (params) {
|
||||||
client.on("ready", function on_ready() {
|
client.on('ready', function on_ready () {
|
||||||
assert.strictEqual(client.monitoring, true, "monitoring after reconnect");
|
assert.strictEqual(client.monitoring, true, 'monitoring after reconnect');
|
||||||
client.removeListener("ready", on_ready);
|
client.removeListener('ready', on_ready);
|
||||||
client.removeListener("reconnecting", on_recon);
|
client.removeListener('reconnecting', on_recon);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.strictEqual(client.monitoring, false, "monitoring off at start");
|
assert.strictEqual(client.monitoring, false, 'monitoring off at start');
|
||||||
client.set("recon 1", "one");
|
client.set('recon 1', 'one');
|
||||||
client.monitor(function (err, res) {
|
client.monitor(function (err, res) {
|
||||||
assert.strictEqual(client.monitoring, true, "monitoring on after monitor()");
|
assert.strictEqual(client.monitoring, true, 'monitoring on after monitor()');
|
||||||
client.set("recon 2", "two", function (err, res) {
|
client.set('recon 2', 'two', function (err, res) {
|
||||||
// Do not do this in normal programs. This is to simulate the server closing on us.
|
// Do not do this in normal programs. This is to simulate the server closing on us.
|
||||||
// For orderly shutdown in normal programs, do client.quit()
|
// For orderly shutdown in normal programs, do client.quit()
|
||||||
client.stream.destroy();
|
client.stream.destroy();
|
||||||
@@ -305,40 +305,40 @@ describe("The node_redis client", function () {
|
|||||||
|
|
||||||
describe("and it's subscribed to a channel", function () {
|
describe("and it's subscribed to a channel", function () {
|
||||||
// "Connection in subscriber mode, only subscriber commands may be used"
|
// "Connection in subscriber mode, only subscriber commands may be used"
|
||||||
it("reconnects, unsubscribes, and can retrieve the pre-existing data", function (done) {
|
it('reconnects, unsubscribes, and can retrieve the pre-existing data', function (done) {
|
||||||
client.on("ready", function on_connect() {
|
client.on('ready', function on_connect () {
|
||||||
client.unsubscribe(helper.isNotError());
|
client.unsubscribe(helper.isNotError());
|
||||||
|
|
||||||
client.on('unsubscribe', function (channel, count) {
|
client.on('unsubscribe', function (channel, count) {
|
||||||
// we should now be out of subscriber mode.
|
// we should now be out of subscriber mode.
|
||||||
assert.strictEqual(channel, "recon channel");
|
assert.strictEqual(channel, 'recon channel');
|
||||||
assert.strictEqual(count, 0);
|
assert.strictEqual(count, 0);
|
||||||
client.set('foo', 'bar', helper.isString('OK', done));
|
client.set('foo', 'bar', helper.isString('OK', done));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
client.set("recon 1", "one");
|
client.set('recon 1', 'one');
|
||||||
client.subscribe("recon channel", function (err, res) {
|
client.subscribe('recon channel', function (err, res) {
|
||||||
// Do not do this in normal programs. This is to simulate the server closing on us.
|
// Do not do this in normal programs. This is to simulate the server closing on us.
|
||||||
// For orderly shutdown in normal programs, do client.quit()
|
// For orderly shutdown in normal programs, do client.quit()
|
||||||
client.stream.destroy();
|
client.stream.destroy();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("reconnects, unsubscribes, and can retrieve the pre-existing data of a explicit channel", function (done) {
|
it('reconnects, unsubscribes, and can retrieve the pre-existing data of a explicit channel', function (done) {
|
||||||
client.on("ready", function on_connect() {
|
client.on('ready', function on_connect () {
|
||||||
client.unsubscribe('recon channel', helper.isNotError());
|
client.unsubscribe('recon channel', helper.isNotError());
|
||||||
|
|
||||||
client.on('unsubscribe', function (channel, count) {
|
client.on('unsubscribe', function (channel, count) {
|
||||||
// we should now be out of subscriber mode.
|
// we should now be out of subscriber mode.
|
||||||
assert.strictEqual(channel, "recon channel");
|
assert.strictEqual(channel, 'recon channel');
|
||||||
assert.strictEqual(count, 0);
|
assert.strictEqual(count, 0);
|
||||||
client.set('foo', 'bar', helper.isString('OK', done));
|
client.set('foo', 'bar', helper.isString('OK', done));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
client.set("recon 1", "one");
|
client.set('recon 1', 'one');
|
||||||
client.subscribe("recon channel", function (err, res) {
|
client.subscribe('recon channel', function (err, res) {
|
||||||
// Do not do this in normal programs. This is to simulate the server closing on us.
|
// Do not do this in normal programs. This is to simulate the server closing on us.
|
||||||
// For orderly shutdown in normal programs, do client.quit()
|
// For orderly shutdown in normal programs, do client.quit()
|
||||||
client.stream.destroy();
|
client.stream.destroy();
|
||||||
@@ -393,10 +393,10 @@ describe("The node_redis client", function () {
|
|||||||
monitorClient.flushdb();
|
monitorClient.flushdb();
|
||||||
monitorClient.monitor(function (err, res) {
|
monitorClient.monitor(function (err, res) {
|
||||||
assert.strictEqual(res, 'OK');
|
assert.strictEqual(res, 'OK');
|
||||||
client.mget("some", "keys", "foo", "bar");
|
client.mget('some', 'keys', 'foo', 'bar');
|
||||||
client.set("json", JSON.stringify({
|
client.set('json', JSON.stringify({
|
||||||
foo: "123",
|
foo: '123',
|
||||||
bar: "sdflkdfsjk",
|
bar: 'sdflkdfsjk',
|
||||||
another: false
|
another: false
|
||||||
}));
|
}));
|
||||||
monitorClient.get('baz', function (err, res) {
|
monitorClient.get('baz', function (err, res) {
|
||||||
@@ -420,7 +420,7 @@ describe("The node_redis client", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
monitorClient.on("monitor", function (time, args, rawOutput) {
|
monitorClient.on('monitor', function (time, args, rawOutput) {
|
||||||
responses.push(args);
|
responses.push(args);
|
||||||
assert(utils.monitor_regex.test(rawOutput), rawOutput);
|
assert(utils.monitor_regex.test(rawOutput), rawOutput);
|
||||||
if (responses.length === 6) {
|
if (responses.length === 6) {
|
||||||
@@ -442,10 +442,10 @@ describe("The node_redis client", function () {
|
|||||||
|
|
||||||
monitorClient.MONITOR(function (err, res) {
|
monitorClient.MONITOR(function (err, res) {
|
||||||
assert.strictEqual(res.inspect(), new Buffer('OK').inspect());
|
assert.strictEqual(res.inspect(), new Buffer('OK').inspect());
|
||||||
client.mget("hello", new Buffer('world'));
|
client.mget('hello', new Buffer('world'));
|
||||||
});
|
});
|
||||||
|
|
||||||
monitorClient.on("monitor", function (time, args, rawOutput) {
|
monitorClient.on('monitor', function (time, args, rawOutput) {
|
||||||
assert.strictEqual(typeof rawOutput, 'string');
|
assert.strictEqual(typeof rawOutput, 'string');
|
||||||
assert(utils.monitor_regex.test(rawOutput), rawOutput);
|
assert(utils.monitor_regex.test(rawOutput), rawOutput);
|
||||||
assert.deepEqual(args, ['mget', 'hello', 'world']);
|
assert.deepEqual(args, ['mget', 'hello', 'world']);
|
||||||
@@ -457,8 +457,8 @@ describe("The node_redis client", function () {
|
|||||||
it('monitors reconnects properly and works with the offline queue', function (done) {
|
it('monitors reconnects properly and works with the offline queue', function (done) {
|
||||||
var i = 0;
|
var i = 0;
|
||||||
client.MONITOR(helper.isString('OK'));
|
client.MONITOR(helper.isString('OK'));
|
||||||
client.mget("hello", 'world');
|
client.mget('hello', 'world');
|
||||||
client.on("monitor", function (time, args, rawOutput) {
|
client.on('monitor', function (time, args, rawOutput) {
|
||||||
assert(utils.monitor_regex.test(rawOutput), rawOutput);
|
assert(utils.monitor_regex.test(rawOutput), rawOutput);
|
||||||
assert.deepEqual(args, ['mget', 'hello', 'world']);
|
assert.deepEqual(args, ['mget', 'hello', 'world']);
|
||||||
if (i++ === 2) {
|
if (i++ === 2) {
|
||||||
@@ -466,7 +466,7 @@ describe("The node_redis client", function () {
|
|||||||
return done();
|
return done();
|
||||||
}
|
}
|
||||||
client.stream.destroy();
|
client.stream.destroy();
|
||||||
client.mget("hello", 'world');
|
client.mget('hello', 'world');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -490,7 +490,7 @@ describe("The node_redis client", function () {
|
|||||||
client.unsubscribe('baz');
|
client.unsubscribe('baz');
|
||||||
}, 150);
|
}, 150);
|
||||||
var called = false;
|
var called = false;
|
||||||
client.on("monitor", function (time, args, rawOutput) {
|
client.on('monitor', function (time, args, rawOutput) {
|
||||||
responses.push(args);
|
responses.push(args);
|
||||||
assert(utils.monitor_regex.test(rawOutput), rawOutput);
|
assert(utils.monitor_regex.test(rawOutput), rawOutput);
|
||||||
if (responses.length === 7) {
|
if (responses.length === 7) {
|
||||||
@@ -531,7 +531,7 @@ describe("The node_redis client", function () {
|
|||||||
end();
|
end();
|
||||||
});
|
});
|
||||||
client.on('idle', function onIdle () {
|
client.on('idle', function onIdle () {
|
||||||
client.removeListener("idle", onIdle);
|
client.removeListener('idle', onIdle);
|
||||||
client.get('foo', helper.isString('bar', end));
|
client.get('foo', helper.isString('bar', end));
|
||||||
});
|
});
|
||||||
client.set('foo', 'bar');
|
client.set('foo', 'bar');
|
||||||
@@ -540,9 +540,9 @@ describe("The node_redis client", function () {
|
|||||||
|
|
||||||
describe('utf8', function () {
|
describe('utf8', function () {
|
||||||
it('handles utf-8 keys', function (done) {
|
it('handles utf-8 keys', function (done) {
|
||||||
var utf8_sample = "ಠ_ಠ";
|
var utf8_sample = 'ಠ_ಠ';
|
||||||
client.set(["utf8test", utf8_sample], helper.isString("OK"));
|
client.set(['utf8test', utf8_sample], helper.isString('OK'));
|
||||||
client.get(["utf8test"], function (err, obj) {
|
client.get(['utf8test'], function (err, obj) {
|
||||||
assert.strictEqual(utf8_sample, obj);
|
assert.strictEqual(utf8_sample, obj);
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
@@ -554,14 +554,14 @@ describe("The node_redis client", function () {
|
|||||||
it('exits subprocess as soon as final command is processed', function (done) {
|
it('exits subprocess as soon as final command is processed', function (done) {
|
||||||
this.timeout(12000);
|
this.timeout(12000);
|
||||||
var args = config.HOST[ip] ? [config.HOST[ip], config.PORT] : [ip];
|
var args = config.HOST[ip] ? [config.HOST[ip], config.PORT] : [ip];
|
||||||
var external = fork("./test/lib/unref.js", args);
|
var external = fork('./test/lib/unref.js', args);
|
||||||
|
|
||||||
var id = setTimeout(function () {
|
var id = setTimeout(function () {
|
||||||
external.kill();
|
external.kill();
|
||||||
return done(Error('unref subprocess timed out'));
|
return done(Error('unref subprocess timed out'));
|
||||||
}, 8000);
|
}, 8000);
|
||||||
|
|
||||||
external.on("close", function (code) {
|
external.on('close', function (code) {
|
||||||
clearTimeout(id);
|
clearTimeout(id);
|
||||||
assert.strictEqual(code, 0);
|
assert.strictEqual(code, 0);
|
||||||
return done();
|
return done();
|
||||||
@@ -612,7 +612,7 @@ describe("The node_redis client", function () {
|
|||||||
|
|
||||||
it("fires client.on('ready')", function (done) {
|
it("fires client.on('ready')", function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.on("ready", function () {
|
client.on('ready', function () {
|
||||||
assert.strictEqual(true, client.options.socket_nodelay);
|
assert.strictEqual(true, client.options.socket_nodelay);
|
||||||
client.quit();
|
client.quit();
|
||||||
|
|
||||||
@@ -624,12 +624,12 @@ describe("The node_redis client", function () {
|
|||||||
|
|
||||||
it('client is functional', function (done) {
|
it('client is functional', function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.on("ready", function () {
|
client.on('ready', function () {
|
||||||
assert.strictEqual(true, client.options.socket_nodelay);
|
assert.strictEqual(true, client.options.socket_nodelay);
|
||||||
client.set(["set key 1", "set val"], helper.isString("OK"));
|
client.set(['set key 1', 'set val'], helper.isString('OK'));
|
||||||
client.set(["set key 2", "set val"], helper.isString("OK"));
|
client.set(['set key 2', 'set val'], helper.isString('OK'));
|
||||||
client.get(["set key 1"], helper.isString("set val"));
|
client.get(['set key 1'], helper.isString('set val'));
|
||||||
client.get(["set key 2"], helper.isString("set val"));
|
client.get(['set key 2'], helper.isString('set val'));
|
||||||
client.quit();
|
client.quit();
|
||||||
|
|
||||||
client.once('end', function () {
|
client.once('end', function () {
|
||||||
@@ -646,7 +646,7 @@ describe("The node_redis client", function () {
|
|||||||
|
|
||||||
it("fires client.on('ready')", function (done) {
|
it("fires client.on('ready')", function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.on("ready", function () {
|
client.on('ready', function () {
|
||||||
assert.strictEqual(false, client.options.socket_nodelay);
|
assert.strictEqual(false, client.options.socket_nodelay);
|
||||||
client.quit();
|
client.quit();
|
||||||
|
|
||||||
@@ -658,12 +658,12 @@ describe("The node_redis client", function () {
|
|||||||
|
|
||||||
it('client is functional', function (done) {
|
it('client is functional', function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.on("ready", function () {
|
client.on('ready', function () {
|
||||||
assert.strictEqual(false, client.options.socket_nodelay);
|
assert.strictEqual(false, client.options.socket_nodelay);
|
||||||
client.set(["set key 1", "set val"], helper.isString("OK"));
|
client.set(['set key 1', 'set val'], helper.isString('OK'));
|
||||||
client.set(["set key 2", "set val"], helper.isString("OK"));
|
client.set(['set key 2', 'set val'], helper.isString('OK'));
|
||||||
client.get(["set key 1"], helper.isString("set val"));
|
client.get(['set key 1'], helper.isString('set val'));
|
||||||
client.get(["set key 2"], helper.isString("set val"));
|
client.get(['set key 2'], helper.isString('set val'));
|
||||||
client.quit();
|
client.quit();
|
||||||
|
|
||||||
client.once('end', function () {
|
client.once('end', function () {
|
||||||
@@ -677,7 +677,7 @@ describe("The node_redis client", function () {
|
|||||||
|
|
||||||
it("fires client.on('ready')", function (done) {
|
it("fires client.on('ready')", function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.on("ready", function () {
|
client.on('ready', function () {
|
||||||
assert.strictEqual(true, client.options.socket_nodelay);
|
assert.strictEqual(true, client.options.socket_nodelay);
|
||||||
client.quit();
|
client.quit();
|
||||||
|
|
||||||
@@ -689,12 +689,12 @@ describe("The node_redis client", function () {
|
|||||||
|
|
||||||
it('client is functional', function (done) {
|
it('client is functional', function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.on("ready", function () {
|
client.on('ready', function () {
|
||||||
assert.strictEqual(true, client.options.socket_nodelay);
|
assert.strictEqual(true, client.options.socket_nodelay);
|
||||||
client.set(["set key 1", "set val"], helper.isString("OK"));
|
client.set(['set key 1', 'set val'], helper.isString('OK'));
|
||||||
client.set(["set key 2", "set val"], helper.isString("OK"));
|
client.set(['set key 2', 'set val'], helper.isString('OK'));
|
||||||
client.get(["set key 1"], helper.isString("set val"));
|
client.get(['set key 1'], helper.isString('set val'));
|
||||||
client.get(["set key 2"], helper.isString("set val"));
|
client.get(['set key 2'], helper.isString('set val'));
|
||||||
client.quit();
|
client.quit();
|
||||||
|
|
||||||
client.once('end', function () {
|
client.once('end', function () {
|
||||||
@@ -706,7 +706,7 @@ describe("The node_redis client", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('retry_max_delay', function () {
|
describe('retry_max_delay', function () {
|
||||||
it("sets upper bound on how long client waits before reconnecting", function (done) {
|
it('sets upper bound on how long client waits before reconnecting', function (done) {
|
||||||
var time;
|
var time;
|
||||||
var timeout = process.platform !== 'win32' ? 20 : 100;
|
var timeout = process.platform !== 'win32' ? 20 : 100;
|
||||||
|
|
||||||
@@ -735,7 +735,7 @@ describe("The node_redis client", function () {
|
|||||||
|
|
||||||
describe('protocol error', function () {
|
describe('protocol error', function () {
|
||||||
|
|
||||||
it("should gracefully recover and only fail on the already send commands", function (done) {
|
it('should gracefully recover and only fail on the already send commands', function (done) {
|
||||||
client = redis.createClient.apply(null, args);
|
client = redis.createClient.apply(null, args);
|
||||||
client.on('error', function (err) {
|
client.on('error', function (err) {
|
||||||
assert.strictEqual(err.message, 'Protocol error, got "a" as reply type byte');
|
assert.strictEqual(err.message, 'Protocol error, got "a" as reply type byte');
|
||||||
@@ -757,7 +757,7 @@ describe("The node_redis client", function () {
|
|||||||
|
|
||||||
describe('enable_offline_queue', function () {
|
describe('enable_offline_queue', function () {
|
||||||
describe('true', function () {
|
describe('true', function () {
|
||||||
it("should emit drain if offline queue is flushed and nothing to buffer", function (done) {
|
it('should emit drain if offline queue is flushed and nothing to buffer', function (done) {
|
||||||
client = redis.createClient({
|
client = redis.createClient({
|
||||||
parser: parser,
|
parser: parser,
|
||||||
no_ready_check: true
|
no_ready_check: true
|
||||||
@@ -779,7 +779,7 @@ describe("The node_redis client", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not return an error and enqueues operation", function (done) {
|
it('does not return an error and enqueues operation', function (done) {
|
||||||
client = redis.createClient(9999, null, {
|
client = redis.createClient(9999, null, {
|
||||||
max_attempts: 0,
|
max_attempts: 0,
|
||||||
parser: parser
|
parser: parser
|
||||||
@@ -794,9 +794,8 @@ describe("The node_redis client", function () {
|
|||||||
if (!finished) {
|
if (!finished) {
|
||||||
// This should never be called
|
// This should never be called
|
||||||
return done(err);
|
return done(err);
|
||||||
} else {
|
|
||||||
assert.strictEqual(err.message, "The command can't be processed. The connection has already been closed.");
|
|
||||||
}
|
}
|
||||||
|
assert.strictEqual(err.message, "The command can't be processed. The connection has already been closed.");
|
||||||
});
|
});
|
||||||
|
|
||||||
return setTimeout(function () {
|
return setTimeout(function () {
|
||||||
@@ -807,7 +806,7 @@ describe("The node_redis client", function () {
|
|||||||
}, 50);
|
}, 50);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("enqueues operation and keep the queue while trying to reconnect", function (done) {
|
it('enqueues operation and keep the queue while trying to reconnect', function (done) {
|
||||||
client = redis.createClient(9999, null, {
|
client = redis.createClient(9999, null, {
|
||||||
max_attempts: 4,
|
max_attempts: 4,
|
||||||
parser: parser
|
parser: parser
|
||||||
@@ -844,21 +843,21 @@ describe("The node_redis client", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("flushes the command queue if connection is lost", function (done) {
|
it('flushes the command queue if connection is lost', function (done) {
|
||||||
client = redis.createClient({
|
client = redis.createClient({
|
||||||
parser: parser
|
parser: parser
|
||||||
});
|
});
|
||||||
|
|
||||||
client.once('ready', function () {
|
client.once('ready', function () {
|
||||||
var multi = client.multi();
|
var multi = client.multi();
|
||||||
multi.config("bar");
|
multi.config('bar');
|
||||||
var cb = function (err, reply) {
|
var cb = function (err, reply) {
|
||||||
assert.equal(err.code, 'UNCERTAIN_STATE');
|
assert.equal(err.code, 'UNCERTAIN_STATE');
|
||||||
};
|
};
|
||||||
for (var i = 0; i < 12; i += 3) {
|
for (var i = 0; i < 12; i += 3) {
|
||||||
client.set("foo" + i, "bar" + i);
|
client.set('foo' + i, 'bar' + i);
|
||||||
multi.set("foo" + (i + 1), "bar" + (i + 1), cb);
|
multi.set('foo' + (i + 1), 'bar' + (i + 1), cb);
|
||||||
multi.set("foo" + (i + 2), "bar" + (i + 2));
|
multi.set('foo' + (i + 2), 'bar' + (i + 2));
|
||||||
}
|
}
|
||||||
multi.exec();
|
multi.exec();
|
||||||
assert.equal(client.command_queue.length, 15);
|
assert.equal(client.command_queue.length, 15);
|
||||||
@@ -894,7 +893,7 @@ describe("The node_redis client", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("emit an error and does not enqueues operation", function (done) {
|
it('emit an error and does not enqueues operation', function (done) {
|
||||||
client = redis.createClient(9999, null, {
|
client = redis.createClient(9999, null, {
|
||||||
parser: parser,
|
parser: parser,
|
||||||
max_attempts: 0,
|
max_attempts: 0,
|
||||||
@@ -919,7 +918,7 @@ describe("The node_redis client", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("flushes the command queue if connection is lost", function (done) {
|
it('flushes the command queue if connection is lost', function (done) {
|
||||||
client = redis.createClient({
|
client = redis.createClient({
|
||||||
parser: parser,
|
parser: parser,
|
||||||
max_attempts: 2,
|
max_attempts: 2,
|
||||||
@@ -928,14 +927,14 @@ describe("The node_redis client", function () {
|
|||||||
|
|
||||||
client.once('ready', function () {
|
client.once('ready', function () {
|
||||||
var multi = client.multi();
|
var multi = client.multi();
|
||||||
multi.config("bar");
|
multi.config('bar');
|
||||||
var cb = function (err, reply) {
|
var cb = function (err, reply) {
|
||||||
assert.equal(err.code, 'UNCERTAIN_STATE');
|
assert.equal(err.code, 'UNCERTAIN_STATE');
|
||||||
};
|
};
|
||||||
for (var i = 0; i < 12; i += 3) {
|
for (var i = 0; i < 12; i += 3) {
|
||||||
client.set("foo" + i, "bar" + i);
|
client.set('foo' + i, 'bar' + i);
|
||||||
multi.set("foo" + (i + 1), "bar" + (i + 1), cb);
|
multi.set('foo' + (i + 1), 'bar' + (i + 1), cb);
|
||||||
multi.set("foo" + (i + 2), "bar" + (i + 2));
|
multi.set('foo' + (i + 2), 'bar' + (i + 2));
|
||||||
}
|
}
|
||||||
multi.exec();
|
multi.exec();
|
||||||
assert.equal(client.command_queue.length, 15);
|
assert.equal(client.command_queue.length, 15);
|
||||||
|
@@ -1,15 +1,15 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require("assert");
|
var assert = require('assert');
|
||||||
var config = require("./lib/config");
|
var config = require('./lib/config');
|
||||||
var helper = require('./helper');
|
var helper = require('./helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
describe("prefix key names", function () {
|
describe('prefix key names', 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 = null;
|
var client = null;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
@@ -28,7 +28,7 @@ describe("prefix key names", function () {
|
|||||||
client.end(true);
|
client.end(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("auto prefix set / get", function (done) {
|
it('auto prefix set / get', function (done) {
|
||||||
client.set('key', 'value', function (err, reply) {
|
client.set('key', 'value', function (err, reply) {
|
||||||
assert.strictEqual(reply, 'OK');
|
assert.strictEqual(reply, 'OK');
|
||||||
});
|
});
|
||||||
@@ -56,7 +56,7 @@ describe("prefix key names", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("auto prefix set / get with .batch", function (done) {
|
it('auto prefix set / get with .batch', function (done) {
|
||||||
var batch = client.batch();
|
var batch = client.batch();
|
||||||
batch.set('key', 'value', function (err, reply) {
|
batch.set('key', 'value', function (err, reply) {
|
||||||
assert.strictEqual(reply, 'OK');
|
assert.strictEqual(reply, 'OK');
|
||||||
@@ -85,7 +85,7 @@ describe("prefix key names", function () {
|
|||||||
batch.exec(done);
|
batch.exec(done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("auto prefix set / get with .multi", function (done) {
|
it('auto prefix set / get with .multi', function (done) {
|
||||||
var multi = client.multi();
|
var multi = client.multi();
|
||||||
multi.set('key', 'value', function (err, reply) {
|
multi.set('key', 'value', function (err, reply) {
|
||||||
assert.strictEqual(reply, 'OK');
|
assert.strictEqual(reply, 'OK');
|
||||||
|
@@ -1,32 +1,32 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require("assert");
|
var assert = require('assert');
|
||||||
var config = require("./lib/config");
|
var config = require('./lib/config');
|
||||||
var helper = require("./helper");
|
var helper = require('./helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
describe("publish/subscribe", function () {
|
describe('publish/subscribe', 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 pub = null;
|
var pub = null;
|
||||||
var sub = null;
|
var sub = null;
|
||||||
var channel = "test channel";
|
var channel = 'test channel';
|
||||||
var channel2 = "test channel 2";
|
var channel2 = 'test channel 2';
|
||||||
var message = "test message";
|
var message = 'test message';
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
var end = helper.callFuncAfter(done, 2);
|
var end = helper.callFuncAfter(done, 2);
|
||||||
|
|
||||||
pub = redis.createClient.apply(redis.createClient, args);
|
pub = redis.createClient.apply(redis.createClient, args);
|
||||||
sub = redis.createClient.apply(redis.createClient, args);
|
sub = redis.createClient.apply(redis.createClient, args);
|
||||||
pub.once("connect", function () {
|
pub.once('connect', function () {
|
||||||
pub.flushdb(function () {
|
pub.flushdb(function () {
|
||||||
end();
|
end();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
sub.once("connect", function () {
|
sub.once('connect', function () {
|
||||||
end();
|
end();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -37,14 +37,14 @@ describe("publish/subscribe", function () {
|
|||||||
sub = redis.createClient({
|
sub = redis.createClient({
|
||||||
disable_resubscribing: true
|
disable_resubscribing: true
|
||||||
});
|
});
|
||||||
sub.once("connect", function () {
|
sub.once('connect', function () {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not fire subscribe events after reconnecting', function (done) {
|
it('does not fire subscribe events after reconnecting', function (done) {
|
||||||
var a = false;
|
var a = false;
|
||||||
sub.on("subscribe", function (chnl, count) {
|
sub.on('subscribe', function (chnl, count) {
|
||||||
if (chnl === channel2) {
|
if (chnl === channel2) {
|
||||||
if (a) {
|
if (a) {
|
||||||
return done(new Error('Test failed'));
|
return done(new Error('Test failed'));
|
||||||
@@ -68,7 +68,7 @@ describe("publish/subscribe", function () {
|
|||||||
describe('subscribe', function () {
|
describe('subscribe', function () {
|
||||||
it('fires a subscribe event for each channel subscribed to even after reconnecting', function (done) {
|
it('fires a subscribe event for each channel subscribed to even after reconnecting', function (done) {
|
||||||
var a = false;
|
var a = false;
|
||||||
sub.on("subscribe", function (chnl, count) {
|
sub.on('subscribe', function (chnl, count) {
|
||||||
if (chnl === channel2) {
|
if (chnl === channel2) {
|
||||||
assert.equal(2, count);
|
assert.equal(2, count);
|
||||||
if (a) {
|
if (a) {
|
||||||
@@ -91,7 +91,7 @@ describe("publish/subscribe", function () {
|
|||||||
sub = redis.createClient({
|
sub = redis.createClient({
|
||||||
detect_buffers: true
|
detect_buffers: true
|
||||||
});
|
});
|
||||||
sub.on("subscribe", function (chnl, count) {
|
sub.on('subscribe', function (chnl, count) {
|
||||||
if (chnl.inspect() === new Buffer([0xAA, 0xBB, 0x00, 0xF0]).inspect()) {
|
if (chnl.inspect() === new Buffer([0xAA, 0xBB, 0x00, 0xF0]).inspect()) {
|
||||||
assert.equal(1, count);
|
assert.equal(1, count);
|
||||||
if (a) {
|
if (a) {
|
||||||
@@ -110,14 +110,14 @@ describe("publish/subscribe", function () {
|
|||||||
|
|
||||||
it('receives messages on subscribed channel', function (done) {
|
it('receives messages on subscribed channel', function (done) {
|
||||||
var end = helper.callFuncAfter(done, 2);
|
var end = helper.callFuncAfter(done, 2);
|
||||||
sub.on("subscribe", function (chnl, count) {
|
sub.on('subscribe', function (chnl, count) {
|
||||||
pub.publish(channel, message, function (err, res) {
|
pub.publish(channel, message, function (err, res) {
|
||||||
helper.isNumber(1)(err, res);
|
helper.isNumber(1)(err, res);
|
||||||
end();
|
end();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
sub.on("message", function (chnl, msg) {
|
sub.on('message', function (chnl, msg) {
|
||||||
assert.equal(chnl, channel);
|
assert.equal(chnl, channel);
|
||||||
assert.equal(msg, message);
|
assert.equal(msg, message);
|
||||||
end();
|
end();
|
||||||
@@ -128,14 +128,14 @@ describe("publish/subscribe", function () {
|
|||||||
|
|
||||||
it('receives messages if subscribe is called after unsubscribe', function (done) {
|
it('receives messages if subscribe is called after unsubscribe', function (done) {
|
||||||
var end = helper.callFuncAfter(done, 2);
|
var end = helper.callFuncAfter(done, 2);
|
||||||
sub.once("subscribe", function (chnl, count) {
|
sub.once('subscribe', function (chnl, count) {
|
||||||
pub.publish(channel, message, function (err, res) {
|
pub.publish(channel, message, function (err, res) {
|
||||||
helper.isNumber(1)(err, res);
|
helper.isNumber(1)(err, res);
|
||||||
end();
|
end();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
sub.on("message", function (chnl, msg) {
|
sub.on('message', function (chnl, msg) {
|
||||||
assert.equal(chnl, channel);
|
assert.equal(chnl, channel);
|
||||||
assert.equal(msg, message);
|
assert.equal(msg, message);
|
||||||
end();
|
end();
|
||||||
@@ -167,10 +167,10 @@ describe("publish/subscribe", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('emits end event if quit is called from within subscribe', function (done) {
|
it('emits end event if quit is called from within subscribe', function (done) {
|
||||||
sub.on("end", function () {
|
sub.on('end', function () {
|
||||||
return done();
|
return done();
|
||||||
});
|
});
|
||||||
sub.on("subscribe", function (chnl, count) {
|
sub.on('subscribe', function (chnl, count) {
|
||||||
sub.quit();
|
sub.quit();
|
||||||
});
|
});
|
||||||
sub.subscribe(channel);
|
sub.subscribe(channel);
|
||||||
@@ -186,29 +186,29 @@ describe("publish/subscribe", function () {
|
|||||||
When it resubscribes, c2 publishes the third message, on the second channel
|
When it resubscribes, c2 publishes the third message, on the second channel
|
||||||
c1 gets the message and drops its connection. When it reconnects, the test ends.
|
c1 gets the message and drops its connection. When it reconnects, the test ends.
|
||||||
*/
|
*/
|
||||||
sub.on("message", function(channel, message) {
|
sub.on('message', function (channel, message) {
|
||||||
if (channel === "chan1") {
|
if (channel === 'chan1') {
|
||||||
assert.strictEqual(message, "hi on channel 1");
|
assert.strictEqual(message, 'hi on channel 1');
|
||||||
sub.stream.end();
|
sub.stream.end();
|
||||||
} else if (channel === "chan2") {
|
} else if (channel === 'chan2') {
|
||||||
assert.strictEqual(message, "hi on channel 2");
|
assert.strictEqual(message, 'hi on channel 2');
|
||||||
sub.stream.end();
|
sub.stream.end();
|
||||||
} else {
|
} else {
|
||||||
sub.quit();
|
sub.quit();
|
||||||
pub.quit();
|
pub.quit();
|
||||||
assert.fail("test failed");
|
assert.fail('test failed');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
sub.subscribe("chan1", "chan2");
|
sub.subscribe('chan1', 'chan2');
|
||||||
|
|
||||||
sub.on("ready", function(err, results) {
|
sub.on('ready', function (err, results) {
|
||||||
count++;
|
count++;
|
||||||
if (count === 1) {
|
if (count === 1) {
|
||||||
pub.publish("chan1", "hi on channel 1");
|
pub.publish('chan1', 'hi on channel 1');
|
||||||
return;
|
return;
|
||||||
} else if (count === 2) {
|
} else if (count === 2) {
|
||||||
pub.publish("chan2", "hi on channel 2");
|
pub.publish('chan2', 'hi on channel 2');
|
||||||
} else {
|
} else {
|
||||||
sub.quit(function () {
|
sub.quit(function () {
|
||||||
pub.quit(function () {
|
pub.quit(function () {
|
||||||
@@ -218,13 +218,13 @@ describe("publish/subscribe", function () {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
pub.publish("chan1", "hi on channel 1");
|
pub.publish('chan1', 'hi on channel 1');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("multiple subscribe / unsubscribe commands", function () {
|
describe('multiple subscribe / unsubscribe commands', function () {
|
||||||
|
|
||||||
it("reconnects properly with pub sub and select command", function (done) {
|
it('reconnects properly with pub sub and select command', function (done) {
|
||||||
var end = helper.callFuncAfter(done, 2);
|
var end = helper.callFuncAfter(done, 2);
|
||||||
sub.select(3);
|
sub.select(3);
|
||||||
sub.set('foo', 'bar');
|
sub.set('foo', 'bar');
|
||||||
@@ -240,7 +240,7 @@ describe("publish/subscribe", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should not go into pubsub mode with unsubscribe commands", function (done) {
|
it('should not go into pubsub mode with unsubscribe commands', function (done) {
|
||||||
sub.on('unsubscribe', function (msg) {
|
sub.on('unsubscribe', function (msg) {
|
||||||
// The unsubscribe should not be triggered, as there was no corresponding channel
|
// The unsubscribe should not be triggered, as there was no corresponding channel
|
||||||
throw new Error('Test failed');
|
throw new Error('Test failed');
|
||||||
@@ -252,7 +252,7 @@ describe("publish/subscribe", function () {
|
|||||||
sub.del('foo', done);
|
sub.del('foo', done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("handles multiple channels with the same channel name properly, even with buffers", function (done) {
|
it('handles multiple channels with the same channel name properly, even with buffers', function (done) {
|
||||||
var channels = ['a', 'b', 'a', new Buffer('a'), 'c', 'b'];
|
var channels = ['a', 'b', 'a', new Buffer('a'), 'c', 'b'];
|
||||||
var subscribed_channels = [1, 2, 2, 2, 3, 3];
|
var subscribed_channels = [1, 2, 2, 2, 3, 3];
|
||||||
var i = 0;
|
var i = 0;
|
||||||
@@ -286,7 +286,7 @@ describe("publish/subscribe", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("unsubscribes, subscribes, unsubscribes... single and multiple entries mixed. Withouth callbacks", function (done) {
|
it('unsubscribes, subscribes, unsubscribes... single and multiple entries mixed. Withouth callbacks', function (done) {
|
||||||
function subscribe (channels) {
|
function subscribe (channels) {
|
||||||
sub.unsubscribe(helper.isNull);
|
sub.unsubscribe(helper.isNull);
|
||||||
sub.subscribe(channels, helper.isNull);
|
sub.subscribe(channels, helper.isNull);
|
||||||
@@ -314,7 +314,7 @@ describe("publish/subscribe", function () {
|
|||||||
subscribe(['5', 'test', 'bla']);
|
subscribe(['5', 'test', 'bla']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("unsubscribes, subscribes, unsubscribes... single and multiple entries mixed. Without callbacks", function (done) {
|
it('unsubscribes, subscribes, unsubscribes... single and multiple entries mixed. Without callbacks', function (done) {
|
||||||
function subscribe (channels) {
|
function subscribe (channels) {
|
||||||
sub.unsubscribe();
|
sub.unsubscribe();
|
||||||
sub.subscribe(channels);
|
sub.subscribe(channels);
|
||||||
@@ -342,7 +342,7 @@ describe("publish/subscribe", function () {
|
|||||||
subscribe(['5', 'test', 'bla']);
|
subscribe(['5', 'test', 'bla']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("unsubscribes, subscribes, unsubscribes... single and multiple entries mixed. Without callback and concret channels", function (done) {
|
it('unsubscribes, subscribes, unsubscribes... single and multiple entries mixed. Without callback and concret channels', function (done) {
|
||||||
function subscribe (channels) {
|
function subscribe (channels) {
|
||||||
sub.unsubscribe(channels);
|
sub.unsubscribe(channels);
|
||||||
sub.unsubscribe(channels);
|
sub.unsubscribe(channels);
|
||||||
@@ -372,7 +372,7 @@ describe("publish/subscribe", function () {
|
|||||||
subscribe(['5', 'test', 'bla']);
|
subscribe(['5', 'test', 'bla']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("unsubscribes, subscribes, unsubscribes... with pattern matching", function (done) {
|
it('unsubscribes, subscribes, unsubscribes... with pattern matching', function (done) {
|
||||||
function subscribe (channels, callback) {
|
function subscribe (channels, callback) {
|
||||||
sub.punsubscribe('prefix:*', helper.isNull);
|
sub.punsubscribe('prefix:*', helper.isNull);
|
||||||
sub.psubscribe(channels, function (err, res) {
|
sub.psubscribe(channels, function (err, res) {
|
||||||
@@ -434,13 +434,13 @@ describe("publish/subscribe", function () {
|
|||||||
|
|
||||||
describe('unsubscribe', function () {
|
describe('unsubscribe', function () {
|
||||||
it('fires an unsubscribe event', function (done) {
|
it('fires an unsubscribe event', function (done) {
|
||||||
sub.on("subscribe", function (chnl, count) {
|
sub.on('subscribe', function (chnl, count) {
|
||||||
sub.unsubscribe(channel);
|
sub.unsubscribe(channel);
|
||||||
});
|
});
|
||||||
|
|
||||||
sub.subscribe(channel);
|
sub.subscribe(channel);
|
||||||
|
|
||||||
sub.on("unsubscribe", function (chnl, count) {
|
sub.on('unsubscribe', function (chnl, count) {
|
||||||
assert.equal(chnl, channel);
|
assert.equal(chnl, channel);
|
||||||
assert.strictEqual(count, 0);
|
assert.strictEqual(count, 0);
|
||||||
return done();
|
return done();
|
||||||
@@ -448,14 +448,14 @@ describe("publish/subscribe", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('puts client back into write mode', function (done) {
|
it('puts client back into write mode', function (done) {
|
||||||
sub.on("subscribe", function (chnl, count) {
|
sub.on('subscribe', function (chnl, count) {
|
||||||
sub.unsubscribe(channel);
|
sub.unsubscribe(channel);
|
||||||
});
|
});
|
||||||
|
|
||||||
sub.subscribe(channel);
|
sub.subscribe(channel);
|
||||||
|
|
||||||
sub.on("unsubscribe", function (chnl, count) {
|
sub.on('unsubscribe', function (chnl, count) {
|
||||||
pub.incr("foo", helper.isNumber(1, done));
|
pub.incr('foo', helper.isNumber(1, done));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -484,7 +484,7 @@ describe("publish/subscribe", function () {
|
|||||||
sub2.on('ready', function () {
|
sub2.on('ready', function () {
|
||||||
sub2.psubscribe('*');
|
sub2.psubscribe('*');
|
||||||
sub2.subscribe('/foo');
|
sub2.subscribe('/foo');
|
||||||
sub2.on("pmessage", function(pattern, channel, message) {
|
sub2.on('pmessage', function (pattern, channel, message) {
|
||||||
assert.strictEqual(pattern.inspect(), new Buffer('*').inspect());
|
assert.strictEqual(pattern.inspect(), new Buffer('*').inspect());
|
||||||
assert.strictEqual(channel.inspect(), new Buffer('/foo').inspect());
|
assert.strictEqual(channel.inspect(), new Buffer('/foo').inspect());
|
||||||
assert.strictEqual(message.inspect(), new Buffer('hello world').inspect());
|
assert.strictEqual(message.inspect(), new Buffer('hello world').inspect());
|
||||||
@@ -539,7 +539,7 @@ describe("publish/subscribe", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should not publish a message multiple times per command", function (done) {
|
it('should not publish a message multiple times per command', function (done) {
|
||||||
var published = {};
|
var published = {};
|
||||||
|
|
||||||
function subscribe (message) {
|
function subscribe (message) {
|
||||||
@@ -572,7 +572,7 @@ describe("publish/subscribe", function () {
|
|||||||
}, 40);
|
}, 40);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should not publish a message without any publish command", function (done) {
|
it('should not publish a message without any publish command', function (done) {
|
||||||
pub.set('foo', 'message');
|
pub.set('foo', 'message');
|
||||||
pub.set('bar', 'hello');
|
pub.set('bar', 'hello');
|
||||||
pub.mget('foo', 'bar');
|
pub.mget('foo', 'bar');
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require("assert");
|
var assert = require('assert');
|
||||||
var config = require("./lib/config");
|
var config = require('./lib/config');
|
||||||
var helper = require('./helper');
|
var helper = require('./helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
@@ -10,7 +10,7 @@ if (process.platform === 'win32') {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("rename commands", function () {
|
describe('rename commands', function () {
|
||||||
before(function (done) {
|
before(function (done) {
|
||||||
helper.stopRedis(function () {
|
helper.stopRedis(function () {
|
||||||
helper.startRedis('./conf/rename.conf', done);
|
helper.startRedis('./conf/rename.conf', done);
|
||||||
@@ -19,7 +19,7 @@ describe("rename commands", 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 = null;
|
var client = null;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
@@ -42,7 +42,7 @@ describe("rename commands", function () {
|
|||||||
client.end(true);
|
client.end(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("allows to use renamed functions", function (done) {
|
it('allows to use renamed functions', function (done) {
|
||||||
if (helper.redisProcess().spawnFailed()) this.skip();
|
if (helper.redisProcess().spawnFailed()) this.skip();
|
||||||
|
|
||||||
client.set('key', 'value', function (err, reply) {
|
client.set('key', 'value', function (err, reply) {
|
||||||
@@ -62,7 +62,7 @@ describe("rename commands", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should also work with batch", function (done) {
|
it('should also work with batch', function (done) {
|
||||||
if (helper.redisProcess().spawnFailed()) this.skip();
|
if (helper.redisProcess().spawnFailed()) this.skip();
|
||||||
|
|
||||||
client.batch([['set', 'key', 'value']]).exec(function (err, res) {
|
client.batch([['set', 'key', 'value']]).exec(function (err, res) {
|
||||||
@@ -79,7 +79,7 @@ describe("rename commands", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should also work with multi", function (done) {
|
it('should also work with multi', function (done) {
|
||||||
if (helper.redisProcess().spawnFailed()) this.skip();
|
if (helper.redisProcess().spawnFailed()) this.skip();
|
||||||
|
|
||||||
client.multi([['set', 'key', 'value']]).exec(function (err, res) {
|
client.multi([['set', 'key', 'value']]).exec(function (err, res) {
|
||||||
@@ -96,7 +96,7 @@ describe("rename commands", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should also work with multi and abort transaction", function (done) {
|
it('should also work with multi and abort transaction', function (done) {
|
||||||
if (helper.redisProcess().spawnFailed()) this.skip();
|
if (helper.redisProcess().spawnFailed()) this.skip();
|
||||||
|
|
||||||
var multi = client.multi();
|
var multi = client.multi();
|
||||||
@@ -116,7 +116,7 @@ describe("rename commands", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should also work prefixed commands", function (done) {
|
it('should also work prefixed commands', function (done) {
|
||||||
if (helper.redisProcess().spawnFailed()) this.skip();
|
if (helper.redisProcess().spawnFailed()) this.skip();
|
||||||
|
|
||||||
client.end(true);
|
client.end(true);
|
||||||
|
@@ -1,15 +1,15 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require("assert");
|
var assert = require('assert');
|
||||||
var config = require("./lib/config");
|
var config = require('./lib/config');
|
||||||
var helper = require('./helper');
|
var helper = require('./helper');
|
||||||
var redis = config.redis;
|
var redis = config.redis;
|
||||||
|
|
||||||
describe("return_buffers", function () {
|
describe('return_buffers', function () {
|
||||||
|
|
||||||
helper.allTests(function (parser, ip, basicArgs) {
|
helper.allTests(function (parser, ip, basicArgs) {
|
||||||
|
|
||||||
describe("using " + parser + " and " + ip, function () {
|
describe('using ' + parser + ' and ' + ip, function () {
|
||||||
var client;
|
var client;
|
||||||
var args = config.configureClient(parser, ip, {
|
var args = config.configureClient(parser, ip, {
|
||||||
return_buffers: true,
|
return_buffers: true,
|
||||||
@@ -30,11 +30,11 @@ describe("return_buffers", function () {
|
|||||||
assert.strictEqual(msg, 'WARNING: You activated return_buffers and detect_buffers at the same time. The return value is always going to be a buffer.');
|
assert.strictEqual(msg, 'WARNING: You activated return_buffers and detect_buffers at the same time. The return value is always going to be a buffer.');
|
||||||
end();
|
end();
|
||||||
});
|
});
|
||||||
client.once("error", done);
|
client.once('error', done);
|
||||||
client.once("connect", function () {
|
client.once('connect', function () {
|
||||||
client.flushdb(function (err) {
|
client.flushdb(function (err) {
|
||||||
client.hmset("hash key 2", "key 1", "val 1", "key 2", "val 2");
|
client.hmset('hash key 2', 'key 1', 'val 1', 'key 2', 'val 2');
|
||||||
client.set("string key 1", "string value");
|
client.set('string key 1', 'string value');
|
||||||
end(err);
|
end(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -43,18 +43,18 @@ describe("return_buffers", function () {
|
|||||||
describe('get', function () {
|
describe('get', function () {
|
||||||
describe('first argument is a string', function () {
|
describe('first argument is a string', function () {
|
||||||
it('returns a buffer', function (done) {
|
it('returns a buffer', function (done) {
|
||||||
client.get("string key 1", function (err, reply) {
|
client.get('string key 1', function (err, reply) {
|
||||||
assert.strictEqual(true, Buffer.isBuffer(reply));
|
assert.strictEqual(true, Buffer.isBuffer(reply));
|
||||||
assert.strictEqual("<Buffer 73 74 72 69 6e 67 20 76 61 6c 75 65>", reply.inspect());
|
assert.strictEqual('<Buffer 73 74 72 69 6e 67 20 76 61 6c 75 65>', reply.inspect());
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns a bufffer when executed as part of transaction', function (done) {
|
it('returns a bufffer when executed as part of transaction', function (done) {
|
||||||
client.multi().get("string key 1").exec(function (err, reply) {
|
client.multi().get('string key 1').exec(function (err, reply) {
|
||||||
assert.strictEqual(1, reply.length);
|
assert.strictEqual(1, reply.length);
|
||||||
assert.strictEqual(true, Buffer.isBuffer(reply[0]));
|
assert.strictEqual(true, Buffer.isBuffer(reply[0]));
|
||||||
assert.strictEqual("<Buffer 73 74 72 69 6e 67 20 76 61 6c 75 65>", reply[0].inspect());
|
assert.strictEqual('<Buffer 73 74 72 69 6e 67 20 76 61 6c 75 65>', reply[0].inspect());
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -64,20 +64,20 @@ describe("return_buffers", function () {
|
|||||||
describe('multi.hget', function () {
|
describe('multi.hget', function () {
|
||||||
it('returns buffers', function (done) {
|
it('returns buffers', function (done) {
|
||||||
client.multi()
|
client.multi()
|
||||||
.hget("hash key 2", "key 1")
|
.hget('hash key 2', 'key 1')
|
||||||
.hget(new Buffer("hash key 2"), "key 1")
|
.hget(new Buffer('hash key 2'), 'key 1')
|
||||||
.hget("hash key 2", new Buffer("key 2"))
|
.hget('hash key 2', new Buffer('key 2'))
|
||||||
.hget("hash key 2", "key 2")
|
.hget('hash key 2', 'key 2')
|
||||||
.exec(function (err, reply) {
|
.exec(function (err, reply) {
|
||||||
assert.strictEqual(true, Array.isArray(reply));
|
assert.strictEqual(true, Array.isArray(reply));
|
||||||
assert.strictEqual(4, reply.length);
|
assert.strictEqual(4, reply.length);
|
||||||
assert.strictEqual("<Buffer 76 61 6c 20 31>", reply[0].inspect());
|
assert.strictEqual('<Buffer 76 61 6c 20 31>', reply[0].inspect());
|
||||||
assert.strictEqual(true, Buffer.isBuffer(reply[1]));
|
assert.strictEqual(true, Buffer.isBuffer(reply[1]));
|
||||||
assert.strictEqual("<Buffer 76 61 6c 20 31>", reply[1].inspect());
|
assert.strictEqual('<Buffer 76 61 6c 20 31>', reply[1].inspect());
|
||||||
assert.strictEqual(true, Buffer.isBuffer(reply[2]));
|
assert.strictEqual(true, Buffer.isBuffer(reply[2]));
|
||||||
assert.strictEqual("<Buffer 76 61 6c 20 32>", reply[2].inspect());
|
assert.strictEqual('<Buffer 76 61 6c 20 32>', reply[2].inspect());
|
||||||
assert.strictEqual(true, Buffer.isBuffer(reply[3]));
|
assert.strictEqual(true, Buffer.isBuffer(reply[3]));
|
||||||
assert.strictEqual("<Buffer 76 61 6c 20 32>", reply[3].inspect());
|
assert.strictEqual('<Buffer 76 61 6c 20 32>', reply[3].inspect());
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -86,20 +86,20 @@ describe("return_buffers", function () {
|
|||||||
describe('batch.hget', function () {
|
describe('batch.hget', function () {
|
||||||
it('returns buffers', function (done) {
|
it('returns buffers', function (done) {
|
||||||
client.batch()
|
client.batch()
|
||||||
.hget("hash key 2", "key 1")
|
.hget('hash key 2', 'key 1')
|
||||||
.hget(new Buffer("hash key 2"), "key 1")
|
.hget(new Buffer('hash key 2'), 'key 1')
|
||||||
.hget("hash key 2", new Buffer("key 2"))
|
.hget('hash key 2', new Buffer('key 2'))
|
||||||
.hget("hash key 2", "key 2")
|
.hget('hash key 2', 'key 2')
|
||||||
.exec(function (err, reply) {
|
.exec(function (err, reply) {
|
||||||
assert.strictEqual(true, Array.isArray(reply));
|
assert.strictEqual(true, Array.isArray(reply));
|
||||||
assert.strictEqual(4, reply.length);
|
assert.strictEqual(4, reply.length);
|
||||||
assert.strictEqual("<Buffer 76 61 6c 20 31>", reply[0].inspect());
|
assert.strictEqual('<Buffer 76 61 6c 20 31>', reply[0].inspect());
|
||||||
assert.strictEqual(true, Buffer.isBuffer(reply[1]));
|
assert.strictEqual(true, Buffer.isBuffer(reply[1]));
|
||||||
assert.strictEqual("<Buffer 76 61 6c 20 31>", reply[1].inspect());
|
assert.strictEqual('<Buffer 76 61 6c 20 31>', reply[1].inspect());
|
||||||
assert.strictEqual(true, Buffer.isBuffer(reply[2]));
|
assert.strictEqual(true, Buffer.isBuffer(reply[2]));
|
||||||
assert.strictEqual("<Buffer 76 61 6c 20 32>", reply[2].inspect());
|
assert.strictEqual('<Buffer 76 61 6c 20 32>', reply[2].inspect());
|
||||||
assert.strictEqual(true, Buffer.isBuffer(reply[3]));
|
assert.strictEqual(true, Buffer.isBuffer(reply[3]));
|
||||||
assert.strictEqual("<Buffer 76 61 6c 20 32>", reply[3].inspect());
|
assert.strictEqual('<Buffer 76 61 6c 20 32>', reply[3].inspect());
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -108,7 +108,7 @@ describe("return_buffers", function () {
|
|||||||
describe('hmget', function () {
|
describe('hmget', function () {
|
||||||
describe('first argument is a string', function () {
|
describe('first argument is a string', function () {
|
||||||
it('handles array of strings with undefined values in transaction (repro #344)', function (done) {
|
it('handles array of strings with undefined values in transaction (repro #344)', function (done) {
|
||||||
client.multi().hmget("hash key 2", "key 3", "key 4").exec(function(err, reply) {
|
client.multi().hmget('hash key 2', 'key 3', 'key 4').exec(function (err, reply) {
|
||||||
assert.strictEqual(true, Array.isArray(reply));
|
assert.strictEqual(true, Array.isArray(reply));
|
||||||
assert.strictEqual(1, reply.length);
|
assert.strictEqual(1, reply.length);
|
||||||
assert.strictEqual(2, reply[0].length);
|
assert.strictEqual(2, reply[0].length);
|
||||||
@@ -121,39 +121,39 @@ describe("return_buffers", function () {
|
|||||||
|
|
||||||
describe('first argument is a buffer', function () {
|
describe('first argument is a buffer', function () {
|
||||||
it('returns buffers for keys requested', function (done) {
|
it('returns buffers for keys requested', function (done) {
|
||||||
client.hmget(new Buffer("hash key 2"), "key 1", "key 2", function (err, reply) {
|
client.hmget(new Buffer('hash key 2'), 'key 1', 'key 2', function (err, reply) {
|
||||||
assert.strictEqual(true, Array.isArray(reply));
|
assert.strictEqual(true, Array.isArray(reply));
|
||||||
assert.strictEqual(2, reply.length);
|
assert.strictEqual(2, reply.length);
|
||||||
assert.strictEqual(true, Buffer.isBuffer(reply[0]));
|
assert.strictEqual(true, Buffer.isBuffer(reply[0]));
|
||||||
assert.strictEqual(true, Buffer.isBuffer(reply[1]));
|
assert.strictEqual(true, Buffer.isBuffer(reply[1]));
|
||||||
assert.strictEqual("<Buffer 76 61 6c 20 31>", reply[0].inspect());
|
assert.strictEqual('<Buffer 76 61 6c 20 31>', reply[0].inspect());
|
||||||
assert.strictEqual("<Buffer 76 61 6c 20 32>", reply[1].inspect());
|
assert.strictEqual('<Buffer 76 61 6c 20 32>', reply[1].inspect());
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns buffers for keys requested in transaction", function (done) {
|
it('returns buffers for keys requested in transaction', function (done) {
|
||||||
client.multi().hmget(new Buffer("hash key 2"), "key 1", "key 2").exec(function (err, reply) {
|
client.multi().hmget(new Buffer('hash key 2'), 'key 1', 'key 2').exec(function (err, reply) {
|
||||||
assert.strictEqual(true, Array.isArray(reply));
|
assert.strictEqual(true, Array.isArray(reply));
|
||||||
assert.strictEqual(1, reply.length);
|
assert.strictEqual(1, reply.length);
|
||||||
assert.strictEqual(2, reply[0].length);
|
assert.strictEqual(2, reply[0].length);
|
||||||
assert.strictEqual(true, Buffer.isBuffer(reply[0][0]));
|
assert.strictEqual(true, Buffer.isBuffer(reply[0][0]));
|
||||||
assert.strictEqual(true, Buffer.isBuffer(reply[0][1]));
|
assert.strictEqual(true, Buffer.isBuffer(reply[0][1]));
|
||||||
assert.strictEqual("<Buffer 76 61 6c 20 31>", reply[0][0].inspect());
|
assert.strictEqual('<Buffer 76 61 6c 20 31>', reply[0][0].inspect());
|
||||||
assert.strictEqual("<Buffer 76 61 6c 20 32>", reply[0][1].inspect());
|
assert.strictEqual('<Buffer 76 61 6c 20 32>', reply[0][1].inspect());
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns buffers for keys requested in .batch", function (done) {
|
it('returns buffers for keys requested in .batch', function (done) {
|
||||||
client.batch().hmget(new Buffer("hash key 2"), "key 1", "key 2").exec(function (err, reply) {
|
client.batch().hmget(new Buffer('hash key 2'), 'key 1', 'key 2').exec(function (err, reply) {
|
||||||
assert.strictEqual(true, Array.isArray(reply));
|
assert.strictEqual(true, Array.isArray(reply));
|
||||||
assert.strictEqual(1, reply.length);
|
assert.strictEqual(1, reply.length);
|
||||||
assert.strictEqual(2, reply[0].length);
|
assert.strictEqual(2, reply[0].length);
|
||||||
assert.strictEqual(true, Buffer.isBuffer(reply[0][0]));
|
assert.strictEqual(true, Buffer.isBuffer(reply[0][0]));
|
||||||
assert.strictEqual(true, Buffer.isBuffer(reply[0][1]));
|
assert.strictEqual(true, Buffer.isBuffer(reply[0][1]));
|
||||||
assert.strictEqual("<Buffer 76 61 6c 20 31>", reply[0][0].inspect());
|
assert.strictEqual('<Buffer 76 61 6c 20 31>', reply[0][0].inspect());
|
||||||
assert.strictEqual("<Buffer 76 61 6c 20 32>", reply[0][1].inspect());
|
assert.strictEqual('<Buffer 76 61 6c 20 32>', reply[0][1].inspect());
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -163,33 +163,33 @@ describe("return_buffers", function () {
|
|||||||
describe('hgetall', function (done) {
|
describe('hgetall', function (done) {
|
||||||
describe('first argument is a string', function () {
|
describe('first argument is a string', function () {
|
||||||
it('returns buffer values', function (done) {
|
it('returns buffer values', function (done) {
|
||||||
client.hgetall("hash key 2", function (err, reply) {
|
client.hgetall('hash key 2', function (err, reply) {
|
||||||
assert.strictEqual("object", typeof reply);
|
assert.strictEqual('object', typeof reply);
|
||||||
assert.strictEqual(2, Object.keys(reply).length);
|
assert.strictEqual(2, Object.keys(reply).length);
|
||||||
assert.strictEqual("<Buffer 76 61 6c 20 31>", reply["key 1"].inspect());
|
assert.strictEqual('<Buffer 76 61 6c 20 31>', reply['key 1'].inspect());
|
||||||
assert.strictEqual("<Buffer 76 61 6c 20 32>", reply["key 2"].inspect());
|
assert.strictEqual('<Buffer 76 61 6c 20 32>', reply['key 2'].inspect());
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns buffer values when executed in transaction', function (done) {
|
it('returns buffer values when executed in transaction', function (done) {
|
||||||
client.multi().hgetall("hash key 2").exec(function (err, reply) {
|
client.multi().hgetall('hash key 2').exec(function (err, reply) {
|
||||||
assert.strictEqual(1, reply.length);
|
assert.strictEqual(1, reply.length);
|
||||||
assert.strictEqual("object", typeof reply[0]);
|
assert.strictEqual('object', typeof reply[0]);
|
||||||
assert.strictEqual(2, Object.keys(reply[0]).length);
|
assert.strictEqual(2, Object.keys(reply[0]).length);
|
||||||
assert.strictEqual("<Buffer 76 61 6c 20 31>", reply[0]["key 1"].inspect());
|
assert.strictEqual('<Buffer 76 61 6c 20 31>', reply[0]['key 1'].inspect());
|
||||||
assert.strictEqual("<Buffer 76 61 6c 20 32>", reply[0]["key 2"].inspect());
|
assert.strictEqual('<Buffer 76 61 6c 20 32>', reply[0]['key 2'].inspect());
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns buffer values when executed in .batch', function (done) {
|
it('returns buffer values when executed in .batch', function (done) {
|
||||||
client.batch().hgetall("hash key 2").exec(function (err, reply) {
|
client.batch().hgetall('hash key 2').exec(function (err, reply) {
|
||||||
assert.strictEqual(1, reply.length);
|
assert.strictEqual(1, reply.length);
|
||||||
assert.strictEqual("object", typeof reply[0]);
|
assert.strictEqual('object', typeof reply[0]);
|
||||||
assert.strictEqual(2, Object.keys(reply[0]).length);
|
assert.strictEqual(2, Object.keys(reply[0]).length);
|
||||||
assert.strictEqual("<Buffer 76 61 6c 20 31>", reply[0]["key 1"].inspect());
|
assert.strictEqual('<Buffer 76 61 6c 20 31>', reply[0]['key 1'].inspect());
|
||||||
assert.strictEqual("<Buffer 76 61 6c 20 32>", reply[0]["key 2"].inspect());
|
assert.strictEqual('<Buffer 76 61 6c 20 32>', reply[0]['key 2'].inspect());
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -197,40 +197,40 @@ describe("return_buffers", function () {
|
|||||||
|
|
||||||
describe('first argument is a buffer', function () {
|
describe('first argument is a buffer', function () {
|
||||||
it('returns buffer values', function (done) {
|
it('returns buffer values', function (done) {
|
||||||
client.hgetall(new Buffer("hash key 2"), function (err, reply) {
|
client.hgetall(new Buffer('hash key 2'), function (err, reply) {
|
||||||
assert.strictEqual(null, err);
|
assert.strictEqual(null, err);
|
||||||
assert.strictEqual("object", typeof reply);
|
assert.strictEqual('object', typeof reply);
|
||||||
assert.strictEqual(2, Object.keys(reply).length);
|
assert.strictEqual(2, Object.keys(reply).length);
|
||||||
assert.strictEqual(true, Buffer.isBuffer(reply["key 1"]));
|
assert.strictEqual(true, Buffer.isBuffer(reply['key 1']));
|
||||||
assert.strictEqual(true, Buffer.isBuffer(reply["key 2"]));
|
assert.strictEqual(true, Buffer.isBuffer(reply['key 2']));
|
||||||
assert.strictEqual("<Buffer 76 61 6c 20 31>", reply["key 1"].inspect());
|
assert.strictEqual('<Buffer 76 61 6c 20 31>', reply['key 1'].inspect());
|
||||||
assert.strictEqual("<Buffer 76 61 6c 20 32>", reply["key 2"].inspect());
|
assert.strictEqual('<Buffer 76 61 6c 20 32>', reply['key 2'].inspect());
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns buffer values when executed in transaction', function (done) {
|
it('returns buffer values when executed in transaction', function (done) {
|
||||||
client.multi().hgetall(new Buffer("hash key 2")).exec(function (err, reply) {
|
client.multi().hgetall(new Buffer('hash key 2')).exec(function (err, reply) {
|
||||||
assert.strictEqual(1, reply.length);
|
assert.strictEqual(1, reply.length);
|
||||||
assert.strictEqual("object", typeof reply[0]);
|
assert.strictEqual('object', typeof reply[0]);
|
||||||
assert.strictEqual(2, Object.keys(reply[0]).length);
|
assert.strictEqual(2, Object.keys(reply[0]).length);
|
||||||
assert.strictEqual(true, Buffer.isBuffer(reply[0]["key 1"]));
|
assert.strictEqual(true, Buffer.isBuffer(reply[0]['key 1']));
|
||||||
assert.strictEqual(true, Buffer.isBuffer(reply[0]["key 2"]));
|
assert.strictEqual(true, Buffer.isBuffer(reply[0]['key 2']));
|
||||||
assert.strictEqual("<Buffer 76 61 6c 20 31>", reply[0]["key 1"].inspect());
|
assert.strictEqual('<Buffer 76 61 6c 20 31>', reply[0]['key 1'].inspect());
|
||||||
assert.strictEqual("<Buffer 76 61 6c 20 32>", reply[0]["key 2"].inspect());
|
assert.strictEqual('<Buffer 76 61 6c 20 32>', reply[0]['key 2'].inspect());
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns buffer values when executed in .batch', function (done) {
|
it('returns buffer values when executed in .batch', function (done) {
|
||||||
client.batch().hgetall(new Buffer("hash key 2")).exec(function (err, reply) {
|
client.batch().hgetall(new Buffer('hash key 2')).exec(function (err, reply) {
|
||||||
assert.strictEqual(1, reply.length);
|
assert.strictEqual(1, reply.length);
|
||||||
assert.strictEqual("object", typeof reply[0]);
|
assert.strictEqual('object', typeof reply[0]);
|
||||||
assert.strictEqual(2, Object.keys(reply[0]).length);
|
assert.strictEqual(2, Object.keys(reply[0]).length);
|
||||||
assert.strictEqual(true, Buffer.isBuffer(reply[0]["key 1"]));
|
assert.strictEqual(true, Buffer.isBuffer(reply[0]['key 1']));
|
||||||
assert.strictEqual(true, Buffer.isBuffer(reply[0]["key 2"]));
|
assert.strictEqual(true, Buffer.isBuffer(reply[0]['key 2']));
|
||||||
assert.strictEqual("<Buffer 76 61 6c 20 31>", reply[0]["key 1"].inspect());
|
assert.strictEqual('<Buffer 76 61 6c 20 31>', reply[0]['key 1'].inspect());
|
||||||
assert.strictEqual("<Buffer 76 61 6c 20 32>", reply[0]["key 2"].inspect());
|
assert.strictEqual('<Buffer 76 61 6c 20 32>', reply[0]['key 2'].inspect());
|
||||||
return done(err);
|
return done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -240,8 +240,8 @@ describe("return_buffers", function () {
|
|||||||
describe('publish/subscribe', function (done) {
|
describe('publish/subscribe', function (done) {
|
||||||
var pub;
|
var pub;
|
||||||
var sub;
|
var sub;
|
||||||
var channel = "test channel";
|
var channel = 'test channel';
|
||||||
var message = new Buffer("test message");
|
var message = new Buffer('test message');
|
||||||
|
|
||||||
var args = config.configureClient(parser, ip, {
|
var args = config.configureClient(parser, ip, {
|
||||||
return_buffers: true
|
return_buffers: true
|
||||||
@@ -253,7 +253,7 @@ describe("return_buffers", function () {
|
|||||||
|
|
||||||
pub = redis.createClient.apply(redis.createClient, basicArgs);
|
pub = redis.createClient.apply(redis.createClient, basicArgs);
|
||||||
sub = redis.createClient.apply(redis.createClient, args);
|
sub = redis.createClient.apply(redis.createClient, args);
|
||||||
pub.once("connect", function () {
|
pub.once('connect', function () {
|
||||||
pub.flushdb(function () {
|
pub.flushdb(function () {
|
||||||
pubConnected = true;
|
pubConnected = true;
|
||||||
if (subConnected) {
|
if (subConnected) {
|
||||||
@@ -261,7 +261,7 @@ describe("return_buffers", function () {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
sub.once("connect", function () {
|
sub.once('connect', function () {
|
||||||
subConnected = true;
|
subConnected = true;
|
||||||
if (pubConnected) {
|
if (pubConnected) {
|
||||||
done();
|
done();
|
||||||
@@ -270,13 +270,13 @@ describe("return_buffers", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('receives buffer messages', function (done) {
|
it('receives buffer messages', function (done) {
|
||||||
sub.on("subscribe", function (chnl, count) {
|
sub.on('subscribe', function (chnl, count) {
|
||||||
pub.publish(channel, message);
|
pub.publish(channel, message);
|
||||||
});
|
});
|
||||||
|
|
||||||
sub.on("message", function (chnl, msg) {
|
sub.on('message', function (chnl, msg) {
|
||||||
assert.strictEqual(true, Buffer.isBuffer(msg));
|
assert.strictEqual(true, Buffer.isBuffer(msg));
|
||||||
assert.strictEqual("<Buffer 74 65 73 74 20 6d 65 73 73 61 67 65>", msg.inspect());
|
assert.strictEqual('<Buffer 74 65 73 74 20 6d 65 73 73 61 67 65>', msg.inspect());
|
||||||
return done();
|
return done();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var assert = require("assert");
|
var assert = require('assert');
|
||||||
var config = require("./lib/config");
|
var config = require('./lib/config');
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var helper = require('./helper');
|
var helper = require('./helper');
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
@@ -9,9 +9,9 @@ var redis = config.redis;
|
|||||||
var utils = require('../lib/utils');
|
var utils = require('../lib/utils');
|
||||||
|
|
||||||
var tls_options = {
|
var tls_options = {
|
||||||
servername: "redis.js.org",
|
servername: 'redis.js.org',
|
||||||
rejectUnauthorized: true,
|
rejectUnauthorized: true,
|
||||||
ca: [ String(fs.readFileSync(path.resolve(__dirname, "./conf/redis.js.org.cert"))) ]
|
ca: [ String(fs.readFileSync(path.resolve(__dirname, './conf/redis.js.org.cert'))) ]
|
||||||
};
|
};
|
||||||
|
|
||||||
var tls_port = 6380;
|
var tls_port = 6380;
|
||||||
@@ -21,7 +21,7 @@ var skip = false;
|
|||||||
// Wait until stunnel4 is in the travis whitelist
|
// Wait until stunnel4 is in the travis whitelist
|
||||||
// Check: https://github.com/travis-ci/apt-package-whitelist/issues/403
|
// Check: https://github.com/travis-ci/apt-package-whitelist/issues/403
|
||||||
// If this is merged, remove the travis env checks
|
// If this is merged, remove the travis env checks
|
||||||
describe("TLS connection tests", function () {
|
describe('TLS connection tests', function () {
|
||||||
|
|
||||||
before(function (done) {
|
before(function (done) {
|
||||||
// Print the warning when the tests run instead of while starting mocha
|
// Print the warning when the tests run instead of while starting mocha
|
||||||
@@ -50,8 +50,8 @@ describe("TLS connection tests", function () {
|
|||||||
client.end(true);
|
client.end(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("on lost connection", function () {
|
describe('on lost connection', function () {
|
||||||
it("emit an error after max retry timeout and do not try to reconnect afterwards", function (done) {
|
it('emit an error after max retry timeout and do not try to reconnect afterwards', function (done) {
|
||||||
if (skip) this.skip();
|
if (skip) this.skip();
|
||||||
var connect_timeout = 500; // in ms
|
var connect_timeout = 500; // in ms
|
||||||
client = redis.createClient({
|
client = redis.createClient({
|
||||||
@@ -65,7 +65,7 @@ describe("TLS connection tests", function () {
|
|||||||
helper.killConnection(client);
|
helper.killConnection(client);
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on("reconnecting", function (params) {
|
client.on('reconnecting', function (params) {
|
||||||
time += params.delay;
|
time += params.delay;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -80,9 +80,9 @@ describe("TLS connection tests", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when not connected", function () {
|
describe('when not connected', function () {
|
||||||
|
|
||||||
it("connect with host and port provided in the options object", function (done) {
|
it('connect with host and port provided in the options object', function (done) {
|
||||||
if (skip) this.skip();
|
if (skip) this.skip();
|
||||||
client = redis.createClient({
|
client = redis.createClient({
|
||||||
host: 'localhost',
|
host: 'localhost',
|
||||||
@@ -103,7 +103,7 @@ describe("TLS connection tests", function () {
|
|||||||
it('fails to connect because the cert is not correct', function (done) {
|
it('fails to connect because the cert is not correct', function (done) {
|
||||||
if (skip) this.skip();
|
if (skip) this.skip();
|
||||||
var faulty_cert = utils.clone(tls_options);
|
var faulty_cert = utils.clone(tls_options);
|
||||||
faulty_cert.ca = [ String(fs.readFileSync(path.resolve(__dirname, "./conf/faulty.cert"))) ];
|
faulty_cert.ca = [ String(fs.readFileSync(path.resolve(__dirname, './conf/faulty.cert'))) ];
|
||||||
client = redis.createClient({
|
client = redis.createClient({
|
||||||
host: 'localhost',
|
host: 'localhost',
|
||||||
connect_timeout: 1000,
|
connect_timeout: 1000,
|
||||||
|
@@ -152,7 +152,7 @@ describe('createClient options', function () {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it("warns on protocol other than redis in the redis url", function () {
|
it('warns on protocol other than redis in the redis url', function () {
|
||||||
var text = '';
|
var text = '';
|
||||||
var unhookIntercept = intercept(function (data) {
|
var unhookIntercept = intercept(function (data) {
|
||||||
text += data;
|
text += data;
|
||||||
@@ -229,7 +229,7 @@ describe('createClient options', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('faulty data', function () {
|
describe('faulty data', function () {
|
||||||
it("throws on strange connection info", function () {
|
it('throws on strange connection info', function () {
|
||||||
try {
|
try {
|
||||||
unifyOptions(true);
|
unifyOptions(true);
|
||||||
throw new Error('failed');
|
throw new Error('failed');
|
||||||
|
Reference in New Issue
Block a user