You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
chore: use standard
This commit is contained in:
@@ -1,77 +1,75 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var assert = require('assert');
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var intercept = require('intercept-stdout');
|
||||
var assert = require('assert')
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
var intercept = require('intercept-stdout')
|
||||
|
||||
describe("The 'blpop' method", function () {
|
||||
describe('The \'blpop\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
var client
|
||||
var bclient
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var client;
|
||||
var bclient;
|
||||
it('pops value immediately if list contains values', function (done) {
|
||||
bclient = redis.createClient.apply(null, args)
|
||||
redis.debugMode = true
|
||||
var text = ''
|
||||
var unhookIntercept = intercept(function (data) {
|
||||
text += data
|
||||
return ''
|
||||
})
|
||||
client.rpush('blocking list', 'initial value', helper.isNumber(1))
|
||||
unhookIntercept()
|
||||
assert(/^Send 127\.0\.0\.1:6379 id [0-9]+: \*3\r\n\$5\r\nrpush\r\n\$13\r\nblocking list\r\n\$13\r\ninitial value\r\n\n$/.test(text))
|
||||
redis.debugMode = false
|
||||
bclient.blpop('blocking list', 0, function (err, value) {
|
||||
assert.strictEqual(value[0], 'blocking list')
|
||||
assert.strictEqual(value[1], 'initial value')
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done);
|
||||
});
|
||||
});
|
||||
it('pops value immediately if list contains values using array notation', function (done) {
|
||||
bclient = redis.createClient.apply(null, args)
|
||||
client.rpush(['blocking list', 'initial value'], helper.isNumber(1))
|
||||
bclient.blpop(['blocking list', 0], function (err, value) {
|
||||
assert.strictEqual(value[0], 'blocking list')
|
||||
assert.strictEqual(value[1], 'initial value')
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
|
||||
it('pops value immediately if list contains values', function (done) {
|
||||
bclient = redis.createClient.apply(null, args);
|
||||
redis.debugMode = true;
|
||||
var text = '';
|
||||
var unhookIntercept = intercept(function (data) {
|
||||
text += data;
|
||||
return '';
|
||||
});
|
||||
client.rpush('blocking list', 'initial value', helper.isNumber(1));
|
||||
unhookIntercept();
|
||||
assert(/^Send 127\.0\.0\.1:6379 id [0-9]+: \*3\r\n\$5\r\nrpush\r\n\$13\r\nblocking list\r\n\$13\r\ninitial value\r\n\n$/.test(text));
|
||||
redis.debugMode = false;
|
||||
bclient.blpop('blocking list', 0, function (err, value) {
|
||||
assert.strictEqual(value[0], 'blocking list');
|
||||
assert.strictEqual(value[1], 'initial value');
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
it('waits for value if list is not yet populated', function (done) {
|
||||
bclient = redis.createClient.apply(null, args)
|
||||
bclient.blpop('blocking list 2', 5, function (err, value) {
|
||||
assert.strictEqual(value[0], 'blocking list 2')
|
||||
assert.strictEqual(value[1], 'initial value')
|
||||
return done(err)
|
||||
})
|
||||
client.rpush('blocking list 2', 'initial value', helper.isNumber(1))
|
||||
})
|
||||
|
||||
it('pops value immediately if list contains values using array notation', function (done) {
|
||||
bclient = redis.createClient.apply(null, args);
|
||||
client.rpush(['blocking list', 'initial value'], helper.isNumber(1));
|
||||
bclient.blpop(['blocking list', 0], function (err, value) {
|
||||
assert.strictEqual(value[0], 'blocking list');
|
||||
assert.strictEqual(value[1], 'initial value');
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
it('times out after specified time', function (done) {
|
||||
bclient = redis.createClient.apply(null, args)
|
||||
bclient.blpop('blocking list', 1, function (err, res) {
|
||||
assert.strictEqual(res, null)
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
|
||||
it('waits for value if list is not yet populated', function (done) {
|
||||
bclient = redis.createClient.apply(null, args);
|
||||
bclient.blpop('blocking list 2', 5, function (err, value) {
|
||||
assert.strictEqual(value[0], 'blocking list 2');
|
||||
assert.strictEqual(value[1], 'initial value');
|
||||
return done(err);
|
||||
});
|
||||
client.rpush('blocking list 2', 'initial value', helper.isNumber(1));
|
||||
});
|
||||
|
||||
it('times out after specified time', function (done) {
|
||||
bclient = redis.createClient.apply(null, args);
|
||||
bclient.blpop('blocking list', 1, function (err, res) {
|
||||
assert.strictEqual(res, null);
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
bclient.end(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
bclient.end(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,155 +1,148 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var assert = require('assert');
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var Buffer = require('safe-buffer').Buffer
|
||||
var assert = require('assert')
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
|
||||
describe("The 'client' method", function () {
|
||||
describe('The \'client\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
var pattern = /addr=/
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
var pattern = /addr=/;
|
||||
describe('using ' + ip, function () {
|
||||
var client
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var client;
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done)
|
||||
})
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done);
|
||||
});
|
||||
});
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
describe('list', function () {
|
||||
it('lists connected clients', function (done) {
|
||||
client.client('LIST', helper.match(pattern, done))
|
||||
})
|
||||
|
||||
describe('list', function () {
|
||||
it('lists connected clients', function (done) {
|
||||
client.client('LIST', helper.match(pattern, done));
|
||||
});
|
||||
it('lists connected clients when invoked with multi\'s chaining syntax', function (done) {
|
||||
client.multi().client('list', helper.isType.string()).exec(helper.match(pattern, done))
|
||||
})
|
||||
|
||||
it("lists connected clients when invoked with multi's chaining syntax", function (done) {
|
||||
client.multi().client('list', helper.isType.string()).exec(helper.match(pattern, done));
|
||||
});
|
||||
it('lists connected clients when invoked with array syntax on client', function (done) {
|
||||
client.multi().client(['list']).exec(helper.match(pattern, done))
|
||||
})
|
||||
|
||||
it('lists connected clients when invoked with array syntax on client', function (done) {
|
||||
client.multi().client(['list']).exec(helper.match(pattern, done));
|
||||
});
|
||||
it('lists connected clients when invoked with multi\'s array syntax', function (done) {
|
||||
client.multi([
|
||||
['client', 'list']
|
||||
]).exec(helper.match(pattern, done))
|
||||
})
|
||||
})
|
||||
|
||||
it("lists connected clients when invoked with multi's array syntax", function (done) {
|
||||
client.multi([
|
||||
['client', 'list']
|
||||
]).exec(helper.match(pattern, done));
|
||||
});
|
||||
});
|
||||
describe('reply', function () {
|
||||
describe('as normal command', function () {
|
||||
it('on', function (done) {
|
||||
helper.serverVersionAtLeast.call(this, client, [3, 2, 0])
|
||||
assert.strictEqual(client.reply, 'ON')
|
||||
client.client('reply', 'on', helper.isString('OK'))
|
||||
assert.strictEqual(client.reply, 'ON')
|
||||
client.set('foo', 'bar', done)
|
||||
})
|
||||
|
||||
describe('reply', function () {
|
||||
describe('as normal command', function () {
|
||||
it('on', function (done) {
|
||||
helper.serverVersionAtLeast.call(this, client, [3, 2, 0]);
|
||||
assert.strictEqual(client.reply, 'ON');
|
||||
client.client('reply', 'on', helper.isString('OK'));
|
||||
assert.strictEqual(client.reply, 'ON');
|
||||
client.set('foo', 'bar', done);
|
||||
});
|
||||
it('off', function (done) {
|
||||
helper.serverVersionAtLeast.call(this, client, [3, 2, 0])
|
||||
assert.strictEqual(client.reply, 'ON')
|
||||
client.client(Buffer.from('REPLY'), 'OFF', helper.isUndefined())
|
||||
assert.strictEqual(client.reply, 'OFF')
|
||||
client.set('foo', 'bar', helper.isUndefined(done))
|
||||
})
|
||||
|
||||
it('off', function (done) {
|
||||
helper.serverVersionAtLeast.call(this, client, [3, 2, 0]);
|
||||
assert.strictEqual(client.reply, 'ON');
|
||||
client.client(new Buffer('REPLY'), 'OFF', helper.isUndefined());
|
||||
assert.strictEqual(client.reply, 'OFF');
|
||||
client.set('foo', 'bar', helper.isUndefined(done));
|
||||
});
|
||||
it('skip', function (done) {
|
||||
helper.serverVersionAtLeast.call(this, client, [3, 2, 0])
|
||||
assert.strictEqual(client.reply, 'ON')
|
||||
client.client('REPLY', Buffer.from('SKIP'), helper.isUndefined())
|
||||
assert.strictEqual(client.reply, 'SKIP_ONE_MORE')
|
||||
client.set('foo', 'bar', helper.isUndefined())
|
||||
client.get('foo', helper.isString('bar', done))
|
||||
})
|
||||
})
|
||||
|
||||
it('skip', function (done) {
|
||||
helper.serverVersionAtLeast.call(this, client, [3, 2, 0]);
|
||||
assert.strictEqual(client.reply, 'ON');
|
||||
client.client('REPLY', new Buffer('SKIP'), helper.isUndefined());
|
||||
assert.strictEqual(client.reply, 'SKIP_ONE_MORE');
|
||||
client.set('foo', 'bar', helper.isUndefined());
|
||||
client.get('foo', helper.isString('bar', done));
|
||||
});
|
||||
});
|
||||
describe('in a batch context', function () {
|
||||
it('on', function (done) {
|
||||
helper.serverVersionAtLeast.call(this, client, [3, 2, 0])
|
||||
var batch = client.batch()
|
||||
assert.strictEqual(client.reply, 'ON')
|
||||
batch.client('reply', 'on', helper.isString('OK'))
|
||||
assert.strictEqual(client.reply, 'ON')
|
||||
batch.set('foo', 'bar')
|
||||
batch.exec(function (err, res) {
|
||||
assert.deepEqual(res, ['OK', 'OK'])
|
||||
done(err)
|
||||
})
|
||||
})
|
||||
|
||||
describe('in a batch context', function () {
|
||||
it('on', function (done) {
|
||||
helper.serverVersionAtLeast.call(this, client, [3, 2, 0]);
|
||||
var batch = client.batch();
|
||||
assert.strictEqual(client.reply, 'ON');
|
||||
batch.client('reply', 'on', helper.isString('OK'));
|
||||
assert.strictEqual(client.reply, 'ON');
|
||||
batch.set('foo', 'bar');
|
||||
batch.exec(function (err, res) {
|
||||
assert.deepEqual(res, ['OK', 'OK']);
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
it('off', function (done) {
|
||||
helper.serverVersionAtLeast.call(this, client, [3, 2, 0])
|
||||
var batch = client.batch()
|
||||
assert.strictEqual(client.reply, 'ON')
|
||||
batch.set('hello', 'world')
|
||||
batch.client(Buffer.from('REPLY'), Buffer.from('OFF'), helper.isUndefined())
|
||||
batch.set('foo', 'bar', helper.isUndefined())
|
||||
batch.exec(function (err, res) {
|
||||
assert.strictEqual(client.reply, 'OFF')
|
||||
assert.deepEqual(res, ['OK', undefined, undefined])
|
||||
done(err)
|
||||
})
|
||||
})
|
||||
|
||||
it('off', function (done) {
|
||||
helper.serverVersionAtLeast.call(this, client, [3, 2, 0]);
|
||||
var batch = client.batch();
|
||||
assert.strictEqual(client.reply, 'ON');
|
||||
batch.set('hello', 'world');
|
||||
batch.client(new Buffer('REPLY'), new Buffer('OFF'), helper.isUndefined());
|
||||
batch.set('foo', 'bar', helper.isUndefined());
|
||||
batch.exec(function (err, res) {
|
||||
assert.strictEqual(client.reply, 'OFF');
|
||||
assert.deepEqual(res, ['OK', undefined, undefined]);
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
it('skip', function (done) {
|
||||
helper.serverVersionAtLeast.call(this, client, [3, 2, 0])
|
||||
assert.strictEqual(client.reply, 'ON')
|
||||
client.batch()
|
||||
.set('hello', 'world')
|
||||
.client('REPLY', 'SKIP', helper.isUndefined())
|
||||
.set('foo', 'bar', helper.isUndefined())
|
||||
.get('foo')
|
||||
.exec(function (err, res) {
|
||||
assert.strictEqual(client.reply, 'ON')
|
||||
assert.deepEqual(res, ['OK', undefined, undefined, 'bar'])
|
||||
done(err)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('skip', function (done) {
|
||||
helper.serverVersionAtLeast.call(this, client, [3, 2, 0]);
|
||||
assert.strictEqual(client.reply, 'ON');
|
||||
client.batch()
|
||||
.set('hello', 'world')
|
||||
.client('REPLY', 'SKIP', helper.isUndefined())
|
||||
.set('foo', 'bar', helper.isUndefined())
|
||||
.get('foo')
|
||||
.exec(function (err, res) {
|
||||
assert.strictEqual(client.reply, 'ON');
|
||||
assert.deepEqual(res, ['OK', undefined, undefined, 'bar']);
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('setname / getname', function () {
|
||||
var client2
|
||||
|
||||
describe('setname / getname', function () {
|
||||
var client2;
|
||||
beforeEach(function (done) {
|
||||
client2 = redis.createClient.apply(null, args)
|
||||
client2.once('ready', function () {
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client2 = redis.createClient.apply(null, args);
|
||||
client2.once('ready', function () {
|
||||
done();
|
||||
});
|
||||
});
|
||||
afterEach(function () {
|
||||
client2.end(true)
|
||||
})
|
||||
|
||||
afterEach(function () {
|
||||
client2.end(true);
|
||||
});
|
||||
it('sets the name', function (done) {
|
||||
// The querys are auto pipelined and the response is a response to all querys of one client
|
||||
// per chunk. So the execution order is only guaranteed on each client
|
||||
var end = helper.callFuncAfter(done, 2)
|
||||
|
||||
it('sets the name', function (done) {
|
||||
// The querys are auto pipelined and the response is a response to all querys of one client
|
||||
// per chunk. So the execution order is only garanteed on each client
|
||||
var end = helper.callFuncAfter(done, 2);
|
||||
|
||||
client.client('setname', 'RUTH');
|
||||
client2.client('setname', ['RENEE'], helper.isString('OK'));
|
||||
client2.client(['setname', 'MARTIN'], helper.isString('OK'));
|
||||
client2.client('getname', function (err, res) {
|
||||
assert.equal(res, 'MARTIN');
|
||||
end();
|
||||
});
|
||||
client.client('getname', function (err, res) {
|
||||
assert.equal(res, 'RUTH');
|
||||
end();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
client.client('setname', 'RUTH')
|
||||
client2.client('setname', ['RENEE'], helper.isString('OK'))
|
||||
client2.client(['setname', 'MARTIN'], helper.isString('OK'))
|
||||
client2.client('getname', helper.isString('MARTIN', end))
|
||||
client.client('getname', helper.isString('RUTH', end))
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,95 +1,93 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var assert = require('assert');
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var uuid = require('uuid');
|
||||
var assert = require('assert')
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
var uuid = require('uuid')
|
||||
|
||||
describe("The 'dbsize' method", function () {
|
||||
describe('The \'dbsize\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
var key, value
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
beforeEach(function () {
|
||||
key = uuid.v4()
|
||||
value = uuid.v4()
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var key, value;
|
||||
describe('when not connected', function () {
|
||||
var client
|
||||
|
||||
beforeEach(function () {
|
||||
key = uuid.v4();
|
||||
value = uuid.v4();
|
||||
});
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.quit()
|
||||
})
|
||||
client.on('end', done)
|
||||
})
|
||||
|
||||
describe('when not connected', function () {
|
||||
var client;
|
||||
it('reports an error', function (done) {
|
||||
client.dbsize([], function (err, res) {
|
||||
assert(err.message.match(/The connection is already closed/))
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.quit();
|
||||
});
|
||||
client.on('end', done);
|
||||
});
|
||||
describe('when connected', function () {
|
||||
var client
|
||||
|
||||
it('reports an error', function (done) {
|
||||
client.dbsize([], function (err, res) {
|
||||
assert(err.message.match(/The connection is already closed/));
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.flushdb(function (err, res) {
|
||||
helper.isString('OK')(err, res)
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('when connected', function () {
|
||||
var client;
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.flushdb(function (err, res) {
|
||||
helper.isString('OK')(err, res);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
it('returns a zero db size', function (done) {
|
||||
client.dbsize([], function (err, res) {
|
||||
helper.isNotError()(err, res)
|
||||
helper.isType.number()(err, res)
|
||||
assert.strictEqual(res, 0, 'Initial db size should be 0')
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
describe('when more data is added to Redis', function () {
|
||||
var oldSize
|
||||
|
||||
it('returns a zero db size', function (done) {
|
||||
client.dbsize([], function (err, res) {
|
||||
helper.isNotError()(err, res);
|
||||
helper.isType.number()(err, res);
|
||||
assert.strictEqual(res, 0, 'Initial db size should be 0');
|
||||
done();
|
||||
});
|
||||
});
|
||||
beforeEach(function (done) {
|
||||
client.dbsize(function (err, res) {
|
||||
helper.isType.number()(err, res)
|
||||
assert.strictEqual(res, 0, 'Initial db size should be 0')
|
||||
|
||||
describe('when more data is added to Redis', function () {
|
||||
var oldSize;
|
||||
oldSize = res
|
||||
|
||||
beforeEach(function (done) {
|
||||
client.dbsize(function (err, res) {
|
||||
helper.isType.number()(err, res);
|
||||
assert.strictEqual(res, 0, 'Initial db size should be 0');
|
||||
client.set(key, value, function (err, res) {
|
||||
helper.isNotError()(err, res)
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
oldSize = res;
|
||||
|
||||
client.set(key, value, function (err, res) {
|
||||
helper.isNotError()(err, res);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('returns a larger db size', function (done) {
|
||||
client.dbsize([], function (err, res) {
|
||||
helper.isNotError()(err, res);
|
||||
helper.isType.positiveNumber()(err, res);
|
||||
assert.strictEqual(true, (oldSize < res), 'Adding data should increase db size.');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
it('returns a larger db size', function (done) {
|
||||
client.dbsize([], function (err, res) {
|
||||
helper.isNotError()(err, res)
|
||||
helper.isType.positiveNumber()(err, res)
|
||||
assert.strictEqual(true, (oldSize < res), 'Adding data should increase db size.')
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,57 +1,55 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
|
||||
describe("The 'del' method", function () {
|
||||
describe('The \'del\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
var client
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var client;
|
||||
it('allows a single key to be deleted', function (done) {
|
||||
client.set('foo', 'bar')
|
||||
client.del('foo', helper.isNumber(1))
|
||||
client.get('foo', helper.isNull(done))
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done);
|
||||
});
|
||||
});
|
||||
it('allows del to be called on a key that does not exist', function (done) {
|
||||
client.del('foo', helper.isNumber(0, done))
|
||||
})
|
||||
|
||||
it('allows a single key to be deleted', function (done) {
|
||||
client.set('foo', 'bar');
|
||||
client.del('foo', helper.isNumber(1));
|
||||
client.get('foo', helper.isNull(done));
|
||||
});
|
||||
it('allows multiple keys to be deleted', function (done) {
|
||||
client.mset('foo', 'bar', 'apple', 'banana')
|
||||
client.del('foo', 'apple', helper.isNumber(2))
|
||||
client.get('foo', helper.isNull())
|
||||
client.get('apple', helper.isNull(done))
|
||||
})
|
||||
|
||||
it('allows del to be called on a key that does not exist', function (done) {
|
||||
client.del('foo', helper.isNumber(0, done));
|
||||
});
|
||||
it('allows multiple keys to be deleted with the array syntax', function (done) {
|
||||
client.mset('foo', 'bar', 'apple', 'banana')
|
||||
client.del(['foo', 'apple'], helper.isNumber(2))
|
||||
client.get('foo', helper.isNull())
|
||||
client.get('apple', helper.isNull(done))
|
||||
})
|
||||
|
||||
it('allows multiple keys to be deleted', function (done) {
|
||||
client.mset('foo', 'bar', 'apple', 'banana');
|
||||
client.del('foo', 'apple', helper.isNumber(2));
|
||||
client.get('foo', helper.isNull());
|
||||
client.get('apple', helper.isNull(done));
|
||||
});
|
||||
it('allows multiple keys to be deleted with the array syntax and no callback', function (done) {
|
||||
client.mset('foo', 'bar', 'apple', 'banana')
|
||||
client.del(['foo', 'apple'])
|
||||
client.get('foo', helper.isNull())
|
||||
client.get('apple', helper.isNull(done))
|
||||
})
|
||||
|
||||
it('allows multiple keys to be deleted with the array syntax', function (done) {
|
||||
client.mset('foo', 'bar', 'apple', 'banana');
|
||||
client.del(['foo', 'apple'], helper.isNumber(2));
|
||||
client.get('foo', helper.isNull());
|
||||
client.get('apple', helper.isNull(done));
|
||||
});
|
||||
|
||||
it('allows multiple keys to be deleted with the array syntax and no callback', function (done) {
|
||||
client.mset('foo', 'bar', 'apple', 'banana');
|
||||
client.del(['foo', 'apple']);
|
||||
client.get('foo', helper.isNull());
|
||||
client.get('apple', helper.isNull(done));
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,210 +1,196 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var assert = require('assert');
|
||||
var config = require('../lib/config');
|
||||
var crypto = require('crypto');
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var assert = require('assert')
|
||||
var config = require('../lib/config')
|
||||
var crypto = require('crypto')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
|
||||
describe("The 'eval' method", function () {
|
||||
describe('The \'eval\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
var client
|
||||
var source = 'return redis.call(\'set\', \'sha\', \'test\')'
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var client;
|
||||
var source = "return redis.call('set', 'sha', 'test')";
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done);
|
||||
});
|
||||
});
|
||||
it('converts a float to an integer when evaluated', function (done) {
|
||||
client.eval('return 100.5', 0, helper.isNumber(100, done))
|
||||
})
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
it('returns a string', function (done) {
|
||||
client.eval('return \'hello world\'', 0, helper.isString('hello world', done))
|
||||
})
|
||||
|
||||
it('converts a float to an integer when evaluated', function (done) {
|
||||
client.eval('return 100.5', 0, helper.isNumber(100, done));
|
||||
});
|
||||
it('converts boolean true to integer 1', function (done) {
|
||||
client.eval('return true', 0, helper.isNumber(1, done))
|
||||
})
|
||||
|
||||
it('returns a string', function (done) {
|
||||
client.eval("return 'hello world'", 0, helper.isString('hello world', done));
|
||||
});
|
||||
it('converts boolean false to null', function (done) {
|
||||
client.eval('return false', 0, helper.isNull(done))
|
||||
})
|
||||
|
||||
it('converts boolean true to integer 1', function (done) {
|
||||
client.eval('return true', 0, helper.isNumber(1, done));
|
||||
});
|
||||
it('converts lua status code to string representation', function (done) {
|
||||
client.eval('return {ok=\'fine\'}', 0, helper.isString('fine', done))
|
||||
})
|
||||
|
||||
it('converts boolean false to null', function (done) {
|
||||
client.eval('return false', 0, helper.isNull(done));
|
||||
});
|
||||
it('converts lua error to an error response', function (done) {
|
||||
client.eval('return {err=\'this is an error\'}', 0, function (err) {
|
||||
assert(err.code === undefined)
|
||||
helper.isError()(err)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('converts lua status code to string representation', function (done) {
|
||||
client.eval("return {ok='fine'}", 0, helper.isString('fine', done));
|
||||
});
|
||||
it('represents a lua table appropritely', function (done) {
|
||||
client.eval('return {1,2,3,\'ciao\',{1,2}}', 0, function (err, res) {
|
||||
assert.strictEqual(err, null)
|
||||
assert.strictEqual(5, res.length)
|
||||
assert.strictEqual(1, res[0])
|
||||
assert.strictEqual(2, res[1])
|
||||
assert.strictEqual(3, res[2])
|
||||
assert.strictEqual('ciao', res[3])
|
||||
assert.strictEqual(2, res[4].length)
|
||||
assert.strictEqual(1, res[4][0])
|
||||
assert.strictEqual(2, res[4][1])
|
||||
return done()
|
||||
})
|
||||
})
|
||||
|
||||
it('converts lua error to an error response', function (done) {
|
||||
client.eval("return {err='this is an error'}", 0, function (err) {
|
||||
assert(err.code === undefined);
|
||||
helper.isError()(err);
|
||||
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', helper.isDeepEqual(['a', 'b', 'c', 'd'], done))
|
||||
})
|
||||
|
||||
it('represents a lua table appropritely', function (done) {
|
||||
client.eval("return {1,2,3,'ciao',{1,2}}", 0, function (err, res) {
|
||||
assert.strictEqual(5, res.length);
|
||||
assert.strictEqual(1, res[0]);
|
||||
assert.strictEqual(2, res[1]);
|
||||
assert.strictEqual(3, res[2]);
|
||||
assert.strictEqual('ciao', res[3]);
|
||||
assert.strictEqual(2, res[4].length);
|
||||
assert.strictEqual(1, res[4][0]);
|
||||
assert.strictEqual(2, res[4][1]);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
it('allows arguments to be provided in array rather than as multiple parameters', function (done) {
|
||||
client.eval(['return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}', 2, 'a', 'b', 'c', 'd'], helper.isDeepEqual(['a', 'b', 'c', 'd'], 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) {
|
||||
assert.strictEqual(4, res.length);
|
||||
assert.strictEqual('a', res[0]);
|
||||
assert.strictEqual('b', res[1]);
|
||||
assert.strictEqual('c', res[2]);
|
||||
assert.strictEqual('d', res[3]);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
it('allows a script to be executed that accesses the redis API without callback', function (done) {
|
||||
client.eval(source, 0)
|
||||
client.get('sha', helper.isString('test', 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) {
|
||||
assert.strictEqual(4, res.length);
|
||||
assert.strictEqual('a', res[0]);
|
||||
assert.strictEqual('b', res[1]);
|
||||
assert.strictEqual('c', res[2]);
|
||||
assert.strictEqual('d', res[3]);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
describe('evalsha', function () {
|
||||
var sha = crypto.createHash('sha1').update(source).digest('hex')
|
||||
|
||||
it('allows a script to be executed that accesses the redis API without callback', function (done) {
|
||||
client.eval(source, 0);
|
||||
client.get('sha', helper.isString('test', done));
|
||||
});
|
||||
it('allows a script to be executed that accesses the redis API', function (done) {
|
||||
client.eval(source, 0, helper.isString('OK'))
|
||||
client.get('sha', helper.isString('test', done))
|
||||
})
|
||||
|
||||
describe('evalsha', function () {
|
||||
var sha = crypto.createHash('sha1').update(source).digest('hex');
|
||||
it('can execute a script if the SHA exists', function (done) {
|
||||
client.evalsha(sha, 0, helper.isString('OK'))
|
||||
client.get('sha', helper.isString('test', done))
|
||||
})
|
||||
|
||||
it('allows a script to be executed that accesses the redis API', function (done) {
|
||||
client.eval(source, 0, helper.isString('OK'));
|
||||
client.get('sha', helper.isString('test', done));
|
||||
});
|
||||
it('returns an error if SHA does not exist', function (done) {
|
||||
client.evalsha('ffffffffffffffffffffffffffffffffffffffff', 0, helper.isError(done))
|
||||
})
|
||||
|
||||
it('can execute a script if the SHA exists', function (done) {
|
||||
client.evalsha(sha, 0, helper.isString('OK'));
|
||||
client.get('sha', helper.isString('test', done));
|
||||
});
|
||||
it('emit an error if SHA does not exist without any callback', function (done) {
|
||||
client.evalsha('ffffffffffffffffffffffffffffffffffffffff', 0)
|
||||
client.on('error', function (err) {
|
||||
assert.strictEqual(err.code, 'NOSCRIPT')
|
||||
assert(/NOSCRIPT No matching script. Please use EVAL./.test(err.message))
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('returns an error if SHA does not exist', function (done) {
|
||||
client.evalsha('ffffffffffffffffffffffffffffffffffffffff', 0, helper.isError(done));
|
||||
});
|
||||
it('emits an error if SHA does not exist and no callback has been provided', function (done) {
|
||||
client.on('error', function (err) {
|
||||
assert.strictEqual(err.message, 'NOSCRIPT No matching script. Please use EVAL.')
|
||||
done()
|
||||
})
|
||||
client.evalsha('ffffffffffffffffffffffffffffffffffffffff', 0)
|
||||
})
|
||||
})
|
||||
|
||||
it('emit an error if SHA does not exist without any callback', function (done) {
|
||||
client.evalsha('ffffffffffffffffffffffffffffffffffffffff', 0);
|
||||
client.on('error', function (err) {
|
||||
assert.equal(err.code, 'NOSCRIPT');
|
||||
assert(/NOSCRIPT No matching script. Please use EVAL./.test(err.message));
|
||||
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) {
|
||||
if (err) return done(err)
|
||||
client.eval('local foo = redis.call(\'incr\',\'incr key\')\nreturn {type(foo),foo}', 0, function (err, res) {
|
||||
assert.strictEqual(2, res.length)
|
||||
assert.strictEqual('number', res[0])
|
||||
assert.strictEqual(1, res[1])
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('emits an error if SHA does not exist and no callback has been provided', function (done) {
|
||||
client.on('error', function (err) {
|
||||
assert.equal(err.message, 'NOSCRIPT No matching script. Please use EVAL.');
|
||||
done();
|
||||
});
|
||||
client.evalsha('ffffffffffffffffffffffffffffffffffffffff', 0);
|
||||
});
|
||||
});
|
||||
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) {
|
||||
assert.strictEqual(err, null)
|
||||
client.eval('local foo = redis.call(\'get\',\'bulk reply key\'); return {type(foo),foo}', 0, function (err, res) {
|
||||
assert.strictEqual(2, res.length)
|
||||
assert.strictEqual('string', res[0])
|
||||
assert.strictEqual('bulk reply value', res[1])
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('allows a key to be incremented, and performs appropriate conversion from LUA type', function (done) {
|
||||
client.set('incr key', 0, function (err, reply) {
|
||||
if (err) return done(err);
|
||||
client.eval("local foo = redis.call('incr','incr key')\nreturn {type(foo),foo}", 0, function (err, res) {
|
||||
assert.strictEqual(2, res.length);
|
||||
assert.strictEqual('number', res[0]);
|
||||
assert.strictEqual(1, res[1]);
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
it('allows a multi mulk operation to be performed, with the appropriate type conversion', function (done) {
|
||||
client.multi()
|
||||
.del('mylist')
|
||||
.rpush('mylist', 'a')
|
||||
.rpush('mylist', 'b')
|
||||
.rpush('mylist', 'c')
|
||||
.exec(function (err, replies) {
|
||||
if (err) return done(err)
|
||||
client.eval('local foo = redis.call(\'lrange\',\'mylist\',0,-1); return {type(foo),foo[1],foo[2],foo[3],# foo}', 0, function (err, res) {
|
||||
assert.strictEqual(5, res.length)
|
||||
assert.strictEqual('table', res[0])
|
||||
assert.strictEqual('a', res[1])
|
||||
assert.strictEqual('b', res[2])
|
||||
assert.strictEqual('c', res[3])
|
||||
assert.strictEqual(3, res[4])
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
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.eval("local foo = redis.call('get','bulk reply key'); return {type(foo),foo}", 0, function (err, res) {
|
||||
assert.strictEqual(2, res.length);
|
||||
assert.strictEqual('string', res[0]);
|
||||
assert.strictEqual('bulk reply value', res[1]);
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
it('returns an appropriate representation of Lua status reply', function (done) {
|
||||
client.eval('local foo = redis.call(\'set\',\'mykey\',\'myval\'); return {type(foo),foo[\'ok\']}', 0, function (err, res) {
|
||||
assert.strictEqual(2, res.length)
|
||||
assert.strictEqual('table', res[0])
|
||||
assert.strictEqual('OK', res[1])
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
|
||||
it('allows a multi mulk operation to be performed, with the appropriate type conversion', function (done) {
|
||||
client.multi()
|
||||
.del('mylist')
|
||||
.rpush('mylist', 'a')
|
||||
.rpush('mylist', 'b')
|
||||
.rpush('mylist', 'c')
|
||||
.exec(function (err, replies) {
|
||||
if (err) return done(err);
|
||||
client.eval("local foo = redis.call('lrange','mylist',0,-1); return {type(foo),foo[1],foo[2],foo[3],# foo}", 0, function (err, res) {
|
||||
assert.strictEqual(5, res.length);
|
||||
assert.strictEqual('table', res[0]);
|
||||
assert.strictEqual('a', res[1]);
|
||||
assert.strictEqual('b', res[2]);
|
||||
assert.strictEqual('c', res[3]);
|
||||
assert.strictEqual(3, res[4]);
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
it('returns an appropriate representation of a Lua error reply', function (done) {
|
||||
client.set('error reply key', 'error reply value', function (err, res) {
|
||||
if (err) return done(err)
|
||||
client.eval('local foo = redis.pcall(\'incr\',\'error reply key\'); return {type(foo),foo[\'err\']}', 0, function (err, res) {
|
||||
assert.strictEqual(2, res.length)
|
||||
assert.strictEqual('table', res[0])
|
||||
assert.strictEqual('ERR value is not an integer or out of range', res[1])
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('returns an appropriate representation of Lua status reply', function (done) {
|
||||
client.eval("local foo = redis.call('set','mykey','myval'); return {type(foo),foo['ok']}", 0, function (err, res) {
|
||||
assert.strictEqual(2, res.length);
|
||||
assert.strictEqual('table', res[0]);
|
||||
assert.strictEqual('OK', res[1]);
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
|
||||
it('returns an appropriate representation of a Lua error reply', function (done) {
|
||||
client.set('error reply key', 'error reply value', function (err, res) {
|
||||
if (err) return done(err);
|
||||
client.eval("local foo = redis.pcall('incr','error reply key'); return {type(foo),foo['err']}", 0, function (err, res) {
|
||||
assert.strictEqual(2, res.length);
|
||||
assert.strictEqual('table', res[0]);
|
||||
assert.strictEqual('ERR value is not an integer or out of range', res[1]);
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('returns an appropriate representation of a Lua nil reply', function (done) {
|
||||
client.del('nil reply key', function (err, res) {
|
||||
if (err) return done(err);
|
||||
client.eval("local foo = redis.call('get','nil reply key'); return {type(foo),foo == false}", 0, function (err, res) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(2, res.length);
|
||||
assert.strictEqual('boolean', res[0]);
|
||||
assert.strictEqual(1, res[1]);
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
it('returns an appropriate representation of a Lua nil reply', function (done) {
|
||||
client.del('nil reply key', function (err, res) {
|
||||
if (err) return done(err)
|
||||
client.eval('local foo = redis.call(\'get\',\'nil reply key\'); return {type(foo),foo == false}', 0, function (err, res) {
|
||||
if (err) throw err
|
||||
assert.strictEqual(2, res.length)
|
||||
assert.strictEqual('boolean', res[0])
|
||||
assert.strictEqual(1, res[1])
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,40 +1,38 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
|
||||
describe("The 'exists' method", function () {
|
||||
describe('The \'exists\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
var client
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var client;
|
||||
it('returns 1 if the key exists', function (done) {
|
||||
client.set('foo', 'bar')
|
||||
client.exists('foo', helper.isNumber(1, done))
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done);
|
||||
});
|
||||
});
|
||||
it('returns 1 if the key exists with array syntax', function (done) {
|
||||
client.set('foo', 'bar')
|
||||
client.exists(['foo'], helper.isNumber(1, done))
|
||||
})
|
||||
|
||||
it('returns 1 if the key exists', function (done) {
|
||||
client.set('foo', 'bar');
|
||||
client.exists('foo', helper.isNumber(1, done));
|
||||
});
|
||||
it('returns 0 if the key does not exist', function (done) {
|
||||
client.exists('bar', helper.isNumber(0, done))
|
||||
})
|
||||
|
||||
it('returns 1 if the key exists with array syntax', function (done) {
|
||||
client.set('foo', 'bar');
|
||||
client.exists(['foo'], helper.isNumber(1, done));
|
||||
});
|
||||
|
||||
it('returns 0 if the key does not exist', function (done) {
|
||||
client.exists('bar', helper.isNumber(0, done));
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,42 +1,40 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
|
||||
describe("The 'expire' method", function () {
|
||||
describe('The \'expire\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
var client
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var client;
|
||||
it('expires key after timeout', function (done) {
|
||||
client.set(['expiry key', 'bar'], helper.isString('OK'))
|
||||
client.expire('expiry key', '1', helper.isNumber(1))
|
||||
setTimeout(function () {
|
||||
client.exists(['expiry key'], helper.isNumber(0, done))
|
||||
}, 1050)
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done);
|
||||
});
|
||||
});
|
||||
it('expires key after timeout with array syntax', function (done) {
|
||||
client.set(['expiry key', 'bar'], helper.isString('OK'))
|
||||
client.expire(['expiry key', '1'], helper.isNumber(1))
|
||||
setTimeout(function () {
|
||||
client.exists(['expiry key'], helper.isNumber(0, done))
|
||||
}, 1050)
|
||||
})
|
||||
|
||||
it('expires key after timeout', function (done) {
|
||||
client.set(['expiry key', 'bar'], helper.isString('OK'));
|
||||
client.expire('expiry key', '1', helper.isNumber(1));
|
||||
setTimeout(function () {
|
||||
client.exists(['expiry key'], helper.isNumber(0, done));
|
||||
}, 1050);
|
||||
});
|
||||
|
||||
it('expires key after timeout with array syntax', function (done) {
|
||||
client.set(['expiry key', 'bar'], helper.isString('OK'));
|
||||
client.expire(['expiry key', '1'], helper.isNumber(1));
|
||||
setTimeout(function () {
|
||||
client.exists(['expiry key'], helper.isNumber(0, done));
|
||||
}, 1050);
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,105 +1,94 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var assert = require('assert');
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var uuid = require('uuid');
|
||||
var assert = require('assert')
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
var uuid = require('uuid')
|
||||
|
||||
describe("The 'flushdb' method", function () {
|
||||
describe('The \'flushdb\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
var key, key2
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
beforeEach(function () {
|
||||
key = uuid.v4()
|
||||
key2 = uuid.v4()
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var key, key2;
|
||||
describe('when not connected', function () {
|
||||
var client
|
||||
|
||||
beforeEach(function () {
|
||||
key = uuid.v4();
|
||||
key2 = uuid.v4();
|
||||
});
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.quit()
|
||||
})
|
||||
client.on('end', done)
|
||||
})
|
||||
|
||||
describe('when not connected', function () {
|
||||
var client;
|
||||
it('reports an error', function (done) {
|
||||
client.flushdb(function (err, res) {
|
||||
assert(err.message.match(/The connection is already closed/))
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.quit();
|
||||
});
|
||||
client.on('end', done);
|
||||
});
|
||||
describe('when connected', function () {
|
||||
var client
|
||||
|
||||
it('reports an error', function (done) {
|
||||
client.flushdb(function (err, res) {
|
||||
assert(err.message.match(/The connection is already closed/));
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
describe('when connected', function () {
|
||||
var client;
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
done();
|
||||
});
|
||||
});
|
||||
describe('when there is data in Redis', function () {
|
||||
beforeEach(function (done) {
|
||||
client.mset(key, uuid.v4(), key2, uuid.v4(), helper.isNotError())
|
||||
client.dbsize([], function (err, res) {
|
||||
helper.isType.positiveNumber()(err, res)
|
||||
assert.strictEqual(res, 2, 'Two keys should have been inserted')
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
it('deletes all the keys', function (done) {
|
||||
client.flushdb(function (err, res) {
|
||||
assert.strictEqual(err, null)
|
||||
assert.strictEqual(res, 'OK')
|
||||
client.mget(key, key2, function (err, res) {
|
||||
assert.strictEqual(null, err, 'Unexpected error returned')
|
||||
assert.strictEqual(true, Array.isArray(res), 'Results object should be an array.')
|
||||
assert.strictEqual(2, res.length, 'Results array should have length 2.')
|
||||
assert.strictEqual(null, res[0], 'Redis key should have been flushed.')
|
||||
assert.strictEqual(null, res[1], 'Redis key should have been flushed.')
|
||||
done(err)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('when there is data in Redis', function () {
|
||||
it('results in a db size of zero', function (done) {
|
||||
client.flushdb(function (err, res) {
|
||||
assert.strictEqual(err, null)
|
||||
client.dbsize([], helper.isNumber(0, done))
|
||||
})
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client.mset(key, uuid.v4(), key2, uuid.v4(), helper.isNotError());
|
||||
client.dbsize([], function (err, res) {
|
||||
helper.isType.positiveNumber()(err, res);
|
||||
assert.equal(res, 2, 'Two keys should have been inserted');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('deletes all the keys', function (done) {
|
||||
client.flushdb(function (err, res) {
|
||||
assert.equal(res, 'OK');
|
||||
client.mget(key, key2, function (err, res) {
|
||||
assert.strictEqual(null, err, 'Unexpected error returned');
|
||||
assert.strictEqual(true, Array.isArray(res), 'Results object should be an array.');
|
||||
assert.strictEqual(2, res.length, 'Results array should have length 2.');
|
||||
assert.strictEqual(null, res[0], 'Redis key should have been flushed.');
|
||||
assert.strictEqual(null, res[1], 'Redis key should have been flushed.');
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('results in a db size of zero', function (done) {
|
||||
client.flushdb(function (err, res) {
|
||||
client.dbsize([], function (err, res) {
|
||||
helper.isNotError()(err, res);
|
||||
helper.isType.number()(err, res);
|
||||
assert.strictEqual(0, res, 'Flushing db should result in db size 0');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('results in a db size of zero without a callback', function (done) {
|
||||
client.flushdb();
|
||||
setTimeout(function (err, res) {
|
||||
client.dbsize(function (err, res) {
|
||||
helper.isNotError()(err, res);
|
||||
helper.isType.number()(err, res);
|
||||
assert.strictEqual(0, res, 'Flushing db should result in db size 0');
|
||||
done();
|
||||
});
|
||||
}, 25);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
it('results in a db size of zero without a callback', function (done) {
|
||||
client.flushdb()
|
||||
setTimeout(function () {
|
||||
client.dbsize(helper.isNumber(0, done))
|
||||
}, 25)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,35 +1,33 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
|
||||
describe("The 'geoadd' method", function () {
|
||||
describe('The \'geoadd\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
var client
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var client;
|
||||
it('returns 1 if the key exists', function (done) {
|
||||
helper.serverVersionAtLeast.call(this, client, [3, 2, 0])
|
||||
client.geoadd('mycity:21:0:location', '13.361389', '38.115556', 'COR', function (err, res) {
|
||||
console.log(err, res)
|
||||
// geoadd is still in the unstable branch. As soon as it reaches the stable one, activate this test
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done);
|
||||
});
|
||||
});
|
||||
|
||||
it('returns 1 if the key exists', function (done) {
|
||||
helper.serverVersionAtLeast.call(this, client, [3, 2, 0]);
|
||||
client.geoadd('mycity:21:0:location', '13.361389', '38.115556', 'COR', function (err, res) {
|
||||
console.log(err, res);
|
||||
// geoadd is still in the unstable branch. As soon as it reaches the stable one, activate this test
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,95 +1,93 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var assert = require('assert');
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var uuid = require('uuid');
|
||||
var assert = require('assert')
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
var uuid = require('uuid')
|
||||
|
||||
describe("The 'get' method", function () {
|
||||
describe('The \'get\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
var key, value
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
beforeEach(function () {
|
||||
key = uuid.v4()
|
||||
value = uuid.v4()
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var key, value;
|
||||
describe('when not connected', function () {
|
||||
var client
|
||||
|
||||
beforeEach(function () {
|
||||
key = uuid.v4();
|
||||
value = uuid.v4();
|
||||
});
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.quit()
|
||||
})
|
||||
client.on('end', done)
|
||||
})
|
||||
|
||||
describe('when not connected', function () {
|
||||
var client;
|
||||
it('reports an error', function (done) {
|
||||
client.get(key, function (err, res) {
|
||||
assert(err.message.match(/The connection is already closed/))
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.quit();
|
||||
});
|
||||
client.on('end', done);
|
||||
});
|
||||
it('reports an error promisified', function () {
|
||||
return client.getAsync(key).then(assert, function (err) {
|
||||
assert(err.message.match(/The connection is already closed/))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('reports an error', function (done) {
|
||||
client.get(key, function (err, res) {
|
||||
assert(err.message.match(/The connection is already closed/));
|
||||
done();
|
||||
});
|
||||
});
|
||||
describe('when connected', function () {
|
||||
var client
|
||||
|
||||
it('reports an error promisified', function () {
|
||||
return client.getAsync(key).then(assert, function (err) {
|
||||
assert(err.message.match(/The connection is already closed/));
|
||||
});
|
||||
});
|
||||
});
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
describe('when connected', function () {
|
||||
var client;
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
done();
|
||||
});
|
||||
});
|
||||
describe('when the key exists in Redis', function () {
|
||||
beforeEach(function (done) {
|
||||
client.set(key, value, function (err, res) {
|
||||
helper.isNotError()(err, res)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
it('gets the value correctly', function (done) {
|
||||
client.get(key, function (err, res) {
|
||||
helper.isString(value)(err, res)
|
||||
done(err)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the key exists in Redis', function () {
|
||||
beforeEach(function (done) {
|
||||
client.set(key, value, function (err, res) {
|
||||
helper.isNotError()(err, res);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('should not throw on a get without callback (even if it\'s not useful)', function (done) {
|
||||
client.get(key)
|
||||
client.on('error', function (err) {
|
||||
throw err
|
||||
})
|
||||
setTimeout(done, 25)
|
||||
})
|
||||
})
|
||||
|
||||
it('gets the value correctly', function (done) {
|
||||
client.get(key, function (err, res) {
|
||||
helper.isString(value)(err, res);
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
it("should not throw on a get without callback (even if it's not useful)", function (done) {
|
||||
client.get(key);
|
||||
client.on('error', function (err) {
|
||||
throw err;
|
||||
});
|
||||
setTimeout(done, 25);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the key does not exist in Redis', function () {
|
||||
it('gets a null value', function (done) {
|
||||
client.get(key, function (err, res) {
|
||||
helper.isNull()(err, res);
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('when the key does not exist in Redis', function () {
|
||||
it('gets a null value', function (done) {
|
||||
client.get(key, function (err, res) {
|
||||
helper.isNull()(err, res)
|
||||
done(err)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,105 +1,103 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var assert = require('assert');
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var uuid = require('uuid');
|
||||
var assert = require('assert')
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
var uuid = require('uuid')
|
||||
|
||||
describe("The 'getset' method", function () {
|
||||
describe('The \'getset\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
var key, value, value2
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
beforeEach(function () {
|
||||
key = uuid.v4()
|
||||
value = uuid.v4()
|
||||
value2 = uuid.v4()
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var key, value, value2;
|
||||
describe('when not connected', function () {
|
||||
var client
|
||||
|
||||
beforeEach(function () {
|
||||
key = uuid.v4();
|
||||
value = uuid.v4();
|
||||
value2 = uuid.v4();
|
||||
});
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.quit()
|
||||
})
|
||||
client.on('end', done)
|
||||
})
|
||||
|
||||
describe('when not connected', function () {
|
||||
var client;
|
||||
it('reports an error', function (done) {
|
||||
client.get(key, function (err, res) {
|
||||
assert(err.message.match(/The connection is already closed/))
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.quit();
|
||||
});
|
||||
client.on('end', done);
|
||||
});
|
||||
describe('when connected', function () {
|
||||
var client
|
||||
|
||||
it('reports an error', function (done) {
|
||||
client.get(key, function (err, res) {
|
||||
assert(err.message.match(/The connection is already closed/));
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
describe('when connected', function () {
|
||||
var client;
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
done();
|
||||
});
|
||||
});
|
||||
describe('when the key exists in Redis', function () {
|
||||
beforeEach(function (done) {
|
||||
client.set(key, value, function (err, res) {
|
||||
helper.isNotError()(err, res)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
it('gets the value correctly', function (done) {
|
||||
client.getset(key, value2, function (err, res) {
|
||||
helper.isString(value)(err, res)
|
||||
client.get(key, function (err, res) {
|
||||
helper.isString(value2)(err, res)
|
||||
done(err)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the key exists in Redis', function () {
|
||||
beforeEach(function (done) {
|
||||
client.set(key, value, function (err, res) {
|
||||
helper.isNotError()(err, res);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('gets the value correctly with array syntax', function (done) {
|
||||
client.getset([key, value2], function (err, res) {
|
||||
helper.isString(value)(err, res)
|
||||
client.get(key, function (err, res) {
|
||||
helper.isString(value2)(err, res)
|
||||
done(err)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('gets the value correctly', function (done) {
|
||||
client.getset(key, value2, function (err, res) {
|
||||
helper.isString(value)(err, res);
|
||||
client.get(key, function (err, res) {
|
||||
helper.isString(value2)(err, res);
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
it('gets the value correctly with array syntax style 2', function (done) {
|
||||
client.getset(key, [value2], function (err, res) {
|
||||
helper.isString(value)(err, res)
|
||||
client.get(key, function (err, res) {
|
||||
helper.isString(value2)(err, res)
|
||||
done(err)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('gets the value correctly with array syntax', function (done) {
|
||||
client.getset([key, value2], function (err, res) {
|
||||
helper.isString(value)(err, res);
|
||||
client.get(key, function (err, res) {
|
||||
helper.isString(value2)(err, res);
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('gets the value correctly with array syntax style 2', function (done) {
|
||||
client.getset(key, [value2], function (err, res) {
|
||||
helper.isString(value)(err, res);
|
||||
client.get(key, function (err, res) {
|
||||
helper.isString(value2)(err, res);
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the key does not exist in Redis', function () {
|
||||
it('gets a null value', function (done) {
|
||||
client.getset(key, value, function (err, res) {
|
||||
helper.isNull()(err, res);
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('when the key does not exist in Redis', function () {
|
||||
it('gets a null value', function (done) {
|
||||
client.getset(key, value, function (err, res) {
|
||||
helper.isNull()(err, res)
|
||||
done(err)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,84 +1,82 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var assert = require('assert');
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var Buffer = require('safe-buffer').Buffer
|
||||
var assert = require('assert')
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
|
||||
describe("The 'hgetall' method", function () {
|
||||
describe('The \'hgetall\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
var client
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('regular client', function () {
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var client;
|
||||
it('handles simple keys and values', function (done) {
|
||||
client.hmset(['hosts', 'hasOwnProperty', '1', 'another', '23', 'home', '1234'], helper.isString('OK'))
|
||||
client.hgetall(['hosts'], function (err, obj) {
|
||||
assert.strictEqual(3, Object.keys(obj).length)
|
||||
assert.strictEqual('1', obj.hasOwnProperty.toString())
|
||||
assert.strictEqual('23', obj.another.toString())
|
||||
assert.strictEqual('1234', obj.home.toString())
|
||||
done(err)
|
||||
})
|
||||
})
|
||||
|
||||
describe('regular client', function () {
|
||||
it('handles fetching keys set using an object', function (done) {
|
||||
client.batch().hmset('msgTest', { message: 'hello' }, undefined).exec()
|
||||
client.hgetall('msgTest', function (err, obj) {
|
||||
assert.strictEqual(1, Object.keys(obj).length)
|
||||
assert.strictEqual(obj.message, 'hello')
|
||||
done(err)
|
||||
})
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done);
|
||||
});
|
||||
});
|
||||
it('handles fetching a messing key', function (done) {
|
||||
client.hgetall('missing', function (err, obj) {
|
||||
assert.strictEqual(null, obj)
|
||||
done(err)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('handles simple keys and values', function (done) {
|
||||
client.hmset(['hosts', 'hasOwnProperty', '1', 'another', '23', 'home', '1234'], helper.isString('OK'));
|
||||
client.hgetall(['hosts'], function (err, obj) {
|
||||
assert.strictEqual(3, Object.keys(obj).length);
|
||||
assert.strictEqual('1', obj.hasOwnProperty.toString());
|
||||
assert.strictEqual('23', obj.another.toString());
|
||||
assert.strictEqual('1234', obj.home.toString());
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
describe('binary client', function () {
|
||||
var client
|
||||
var args = config.configureClient(ip, {
|
||||
returnBuffers: true
|
||||
})
|
||||
|
||||
it('handles fetching keys set using an object', function (done) {
|
||||
client.batch().hmset('msgTest', { message: 'hello' }, undefined).exec();
|
||||
client.hgetall('msgTest', function (err, obj) {
|
||||
assert.strictEqual(1, Object.keys(obj).length);
|
||||
assert.strictEqual(obj.message, 'hello');
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done)
|
||||
})
|
||||
})
|
||||
|
||||
it('handles fetching a messing key', function (done) {
|
||||
client.hgetall('missing', function (err, obj) {
|
||||
assert.strictEqual(null, obj);
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
it('returns binary results', function (done) {
|
||||
client.hmset(['bhosts', 'mjr', '1', 'another', '23', 'home', '1234', Buffer.from([0xAA, 0xBB, 0x00, 0xF0]), Buffer.from([0xCC, 0xDD, 0x00, 0xF0])], helper.isString('OK'))
|
||||
client.hgetall('bhosts', function (err, obj) {
|
||||
assert.strictEqual(4, Object.keys(obj).length)
|
||||
assert.strictEqual('1', obj.mjr.toString())
|
||||
assert.strictEqual('23', obj.another.toString())
|
||||
assert.strictEqual('1234', obj.home.toString())
|
||||
assert.strictEqual((Buffer.from([0xAA, 0xBB, 0x00, 0xF0])).toString('binary'), Object.keys(obj)[3])
|
||||
assert.strictEqual((Buffer.from([0xCC, 0xDD, 0x00, 0xF0])).toString('binary'), obj[(Buffer.from([0xAA, 0xBB, 0x00, 0xF0])).toString('binary')].toString('binary'))
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('binary client', function () {
|
||||
var client;
|
||||
var args = config.configureClient(ip, {
|
||||
returnBuffers: true
|
||||
});
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done);
|
||||
});
|
||||
});
|
||||
|
||||
it('returns binary results', function (done) {
|
||||
client.hmset(['bhosts', 'mjr', '1', 'another', '23', 'home', '1234', new Buffer([0xAA, 0xBB, 0x00, 0xF0]), new Buffer([0xCC, 0xDD, 0x00, 0xF0])], helper.isString('OK'));
|
||||
client.hgetall('bhosts', function (err, obj) {
|
||||
assert.strictEqual(4, Object.keys(obj).length);
|
||||
assert.strictEqual('1', obj.mjr.toString());
|
||||
assert.strictEqual('23', obj.another.toString());
|
||||
assert.strictEqual('1234', obj.home.toString());
|
||||
assert.strictEqual((new Buffer([0xAA, 0xBB, 0x00, 0xF0])).toString('binary'), Object.keys(obj)[3]);
|
||||
assert.strictEqual((new Buffer([0xCC, 0xDD, 0x00, 0xF0])).toString('binary'), obj[(new Buffer([0xAA, 0xBB, 0x00, 0xF0])).toString('binary')].toString('binary'));
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,40 +1,38 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
|
||||
describe("The 'hincrby' method", function () {
|
||||
describe('The \'hincrby\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
var client
|
||||
var hash = 'test hash'
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var client;
|
||||
var hash = 'test hash';
|
||||
it('increments a key that has already been set', function (done) {
|
||||
var field = 'field 1'
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done);
|
||||
});
|
||||
});
|
||||
client.hset(hash, field, 33)
|
||||
client.hincrby(hash, field, 10, helper.isNumber(43, done))
|
||||
})
|
||||
|
||||
it('increments a key that has already been set', function (done) {
|
||||
var field = 'field 1';
|
||||
it('increments a key that has not been set', function (done) {
|
||||
var field = 'field 2'
|
||||
|
||||
client.hset(hash, field, 33);
|
||||
client.hincrby(hash, field, 10, helper.isNumber(43, done));
|
||||
});
|
||||
client.hincrby(hash, field, 10, helper.isNumber(10, done))
|
||||
})
|
||||
|
||||
it('increments a key that has not been set', function (done) {
|
||||
var field = 'field 2';
|
||||
|
||||
client.hincrby(hash, field, 10, helper.isNumber(10, done));
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,38 +1,37 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var Buffer = require('safe-buffer').Buffer
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
|
||||
describe("The 'hlen' method", function () {
|
||||
describe('The \'hlen\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
var client
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var client;
|
||||
it('reports the count of keys', function (done) {
|
||||
var hash = 'test hash'
|
||||
var field1 = Buffer.from('0123456789')
|
||||
var value1 = Buffer.from('abcdefghij')
|
||||
var field2 = Buffer.from('')
|
||||
var value2 = Buffer.from('')
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done);
|
||||
});
|
||||
});
|
||||
client.hset(hash, field1, value1, helper.isNumber(1))
|
||||
client.hset(hash, field2, value2, helper.isNumber(1))
|
||||
client.hlen(hash, helper.isNumber(2, done))
|
||||
})
|
||||
|
||||
it('reports the count of keys', function (done) {
|
||||
var hash = 'test hash';
|
||||
var field1 = new Buffer('0123456789');
|
||||
var value1 = new Buffer('abcdefghij');
|
||||
var field2 = new Buffer(0);
|
||||
var value2 = new Buffer(0);
|
||||
|
||||
client.hset(hash, field1, value1, helper.isNumber(1));
|
||||
client.hset(hash, field2, value2, helper.isNumber(1));
|
||||
client.hlen(hash, helper.isNumber(2, done));
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,71 +1,69 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var assert = require('assert');
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var assert = require('assert')
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
|
||||
describe("The 'hmget' method", function () {
|
||||
describe('The \'hmget\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
var client
|
||||
var hash = 'test hash'
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('error', done)
|
||||
client.once('ready', function () {
|
||||
client.flushdb()
|
||||
client.hmset(hash, {'0123456789': 'abcdefghij', 'some manner of key': 'a type of value'}, helper.isString('OK', done))
|
||||
})
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var client;
|
||||
var hash = 'test hash';
|
||||
it('allows keys to be specified using multiple arguments', function (done) {
|
||||
client.hmget(hash, '0123456789', 'some manner of key', function (err, reply) {
|
||||
assert.strictEqual('abcdefghij', reply[0].toString())
|
||||
assert.strictEqual('a type of value', reply[1].toString())
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('error', done);
|
||||
client.once('ready', function () {
|
||||
client.flushdb();
|
||||
client.hmset(hash, {'0123456789': 'abcdefghij', 'some manner of key': 'a type of value'}, helper.isString('OK', done));
|
||||
});
|
||||
});
|
||||
it('allows keys to be specified by passing an array without manipulating the array', function (done) {
|
||||
var data = ['0123456789', 'some manner of key']
|
||||
client.hmget(hash, data, function (err, reply) {
|
||||
assert.strictEqual(data.length, 2)
|
||||
assert.strictEqual('abcdefghij', reply[0].toString())
|
||||
assert.strictEqual('a type of value', reply[1].toString())
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
|
||||
it('allows keys to be specified using multiple arguments', function (done) {
|
||||
client.hmget(hash, '0123456789', 'some manner of key', function (err, reply) {
|
||||
assert.strictEqual('abcdefghij', reply[0].toString());
|
||||
assert.strictEqual('a type of value', reply[1].toString());
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
it('allows keys to be specified by passing an array as first argument', function (done) {
|
||||
client.hmget([hash, '0123456789', 'some manner of key'], function (err, reply) {
|
||||
assert.strictEqual('abcdefghij', reply[0].toString())
|
||||
assert.strictEqual('a type of value', reply[1].toString())
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
|
||||
it('allows keys to be specified by passing an array without manipulating the array', function (done) {
|
||||
var data = ['0123456789', 'some manner of key'];
|
||||
client.hmget(hash, data, function (err, reply) {
|
||||
assert.strictEqual(data.length, 2);
|
||||
assert.strictEqual('abcdefghij', reply[0].toString());
|
||||
assert.strictEqual('a type of value', reply[1].toString());
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
it('allows a single key to be specified in an array', function (done) {
|
||||
client.hmget(hash, ['0123456789'], function (err, reply) {
|
||||
assert.strictEqual('abcdefghij', reply[0].toString())
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
|
||||
it('allows keys to be specified by passing an array as first argument', function (done) {
|
||||
client.hmget([hash, '0123456789', 'some manner of key'], function (err, reply) {
|
||||
assert.strictEqual('abcdefghij', reply[0].toString());
|
||||
assert.strictEqual('a type of value', reply[1].toString());
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
it('allows keys to be specified that have not yet been set', function (done) {
|
||||
client.hmget(hash, 'missing thing', 'another missing thing', function (err, reply) {
|
||||
assert.strictEqual(null, reply[0])
|
||||
assert.strictEqual(null, reply[1])
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
|
||||
it('allows a single key to be specified in an array', function (done) {
|
||||
client.hmget(hash, ['0123456789'], function (err, reply) {
|
||||
assert.strictEqual('abcdefghij', reply[0].toString());
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
|
||||
it('allows keys to be specified that have not yet been set', function (done) {
|
||||
client.hmget(hash, 'missing thing', 'another missing thing', function (err, reply) {
|
||||
assert.strictEqual(null, reply[0]);
|
||||
assert.strictEqual(null, reply[1]);
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,117 +1,115 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var assert = require('assert');
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var assert = require('assert')
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
|
||||
describe("The 'hmset' method", function () {
|
||||
describe('The \'hmset\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
var client
|
||||
var hash = 'test hash'
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var client;
|
||||
var hash = 'test hash';
|
||||
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.hgetall(hash, function (err, obj) {
|
||||
assert.strictEqual(obj['0123456789'], 'abcdefghij')
|
||||
assert.strictEqual(obj['some manner of key'], 'a type of value')
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.flushdb(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.hgetall(hash, function (err, obj) {
|
||||
assert.strictEqual(obj['0123456789'], 'abcdefghij')
|
||||
assert.strictEqual(obj['some manner of key'], 'a type of value')
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
|
||||
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.hgetall(hash, function (err, obj) {
|
||||
assert.equal(obj['0123456789'], 'abcdefghij');
|
||||
assert.equal(obj['some manner of key'], 'a type of value');
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
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}, undefined)
|
||||
client.hgetall(231232, function (err, obj) {
|
||||
assert.strictEqual(obj['0123456789'], 'abcdefghij')
|
||||
assert.strictEqual(obj['some manner of key'], 'a type of value')
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
|
||||
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.hgetall(hash, function (err, obj) {
|
||||
assert.equal(obj['0123456789'], 'abcdefghij');
|
||||
assert.equal(obj['some manner of key'], 'a type of value');
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
it('allows a numeric key', function (done) {
|
||||
client.hmset(hash, 99, 'banana', helper.isString('OK'))
|
||||
client.hgetall(hash, function (err, obj) {
|
||||
assert.strictEqual(obj['99'], 'banana')
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
|
||||
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}, undefined);
|
||||
client.hgetall(231232, function (err, obj) {
|
||||
assert.equal(obj['0123456789'], 'abcdefghij');
|
||||
assert.equal(obj['some manner of key'], 'a type of value');
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
it('allows a numeric key without callback', function (done) {
|
||||
client.hmset(hash, 99, 'banana', 'test', 25)
|
||||
client.hgetall(hash, function (err, obj) {
|
||||
assert.strictEqual(obj['99'], 'banana')
|
||||
assert.strictEqual(obj.test, '25')
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
|
||||
it('allows a numeric key', function (done) {
|
||||
client.hmset(hash, 99, 'banana', helper.isString('OK'));
|
||||
client.hgetall(hash, function (err, obj) {
|
||||
assert.equal(obj['99'], 'banana');
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
it('allows an array without callback', function (done) {
|
||||
client.hmset([hash, 99, 'banana', 'test', 25])
|
||||
client.hgetall(hash, function (err, obj) {
|
||||
assert.strictEqual(obj['99'], 'banana')
|
||||
assert.strictEqual(obj.test, '25')
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
|
||||
it('allows a numeric key without callback', function (done) {
|
||||
client.hmset(hash, 99, 'banana', 'test', 25);
|
||||
client.hgetall(hash, function (err, obj) {
|
||||
assert.equal(obj['99'], 'banana');
|
||||
assert.equal(obj.test, '25');
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
it('allows an array and a callback', function (done) {
|
||||
client.hmset([hash, 99, 'banana', 'test', 25], helper.isString('OK'))
|
||||
client.hgetall(hash, function (err, obj) {
|
||||
assert.strictEqual(obj['99'], 'banana')
|
||||
assert.strictEqual(obj.test, '25')
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
|
||||
it('allows an array without callback', function (done) {
|
||||
client.hmset([hash, 99, 'banana', 'test', 25]);
|
||||
client.hgetall(hash, function (err, obj) {
|
||||
assert.equal(obj['99'], 'banana');
|
||||
assert.equal(obj.test, '25');
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
it('allows a key plus array without callback', function (done) {
|
||||
client.hmset(hash, [99, 'banana', 'test', 25])
|
||||
client.hgetall(hash, function (err, obj) {
|
||||
assert.strictEqual(obj['99'], 'banana')
|
||||
assert.strictEqual(obj.test, '25')
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
|
||||
it('allows an array and a callback', function (done) {
|
||||
client.hmset([hash, 99, 'banana', 'test', 25], helper.isString('OK'));
|
||||
client.hgetall(hash, function (err, obj) {
|
||||
assert.equal(obj['99'], 'banana');
|
||||
assert.equal(obj.test, '25');
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
it('allows a key plus array and a callback', function (done) {
|
||||
client.hmset(hash, [99, 'banana', 'test', 25], helper.isString('OK'))
|
||||
client.hgetall(hash, function (err, obj) {
|
||||
assert.strictEqual(obj['99'], 'banana')
|
||||
assert.strictEqual(obj.test, '25')
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
|
||||
it('allows a key plus array without callback', function (done) {
|
||||
client.hmset(hash, [99, 'banana', 'test', 25]);
|
||||
client.hgetall(hash, function (err, obj) {
|
||||
assert.equal(obj['99'], 'banana');
|
||||
assert.equal(obj.test, '25');
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
it('handles object-style syntax without callback', function (done) {
|
||||
client.hmset(hash, {'0123456789': 'abcdefghij', 'some manner of key': 'a type of value'})
|
||||
client.hgetall(hash, function (err, obj) {
|
||||
assert.strictEqual(obj['0123456789'], 'abcdefghij')
|
||||
assert.strictEqual(obj['some manner of key'], 'a type of value')
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
|
||||
it('allows a key plus array and a callback', function (done) {
|
||||
client.hmset(hash, [99, 'banana', 'test', 25], helper.isString('OK'));
|
||||
client.hgetall(hash, function (err, obj) {
|
||||
assert.equal(obj['99'], 'banana');
|
||||
assert.equal(obj.test, '25');
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
|
||||
it('handles object-style syntax without callback', function (done) {
|
||||
client.hmset(hash, {'0123456789': 'abcdefghij', 'some manner of key': 'a type of value'});
|
||||
client.hgetall(hash, function (err, obj) {
|
||||
assert.equal(obj['0123456789'], 'abcdefghij');
|
||||
assert.equal(obj['some manner of key'], 'a type of value');
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,91 +1,91 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var assert = require('assert');
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var Buffer = require('safe-buffer').Buffer
|
||||
var assert = require('assert')
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
|
||||
describe("The 'hset' method", function () {
|
||||
describe('The \'hset\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
var client
|
||||
var hash = 'test hash'
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var client;
|
||||
var hash = 'test hash';
|
||||
it('allows a value to be set in a hash', function (done) {
|
||||
var field = Buffer.from('0123456789')
|
||||
var value = Buffer.from('abcdefghij')
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done);
|
||||
});
|
||||
});
|
||||
client.hset(hash, field, value, helper.isNumber(1))
|
||||
client.hget(hash, field, helper.isString(value.toString(), done))
|
||||
})
|
||||
|
||||
it('allows a value to be set in a hash', function (done) {
|
||||
var field = new Buffer('0123456789');
|
||||
var value = new Buffer('abcdefghij');
|
||||
it('handles an empty value', function (done) {
|
||||
var field = Buffer.from('0123456789')
|
||||
var value = Buffer.from('')
|
||||
|
||||
client.hset(hash, field, value, helper.isNumber(1));
|
||||
client.hget(hash, field, helper.isString(value.toString(), done));
|
||||
});
|
||||
client.hset(hash, field, value, helper.isNumber(1))
|
||||
client.hget([hash, field], helper.isString('', done))
|
||||
})
|
||||
|
||||
it('handles an empty value', function (done) {
|
||||
var field = new Buffer('0123456789');
|
||||
var value = new Buffer(0);
|
||||
it('handles empty key and value', function (done) {
|
||||
var field = Buffer.from('')
|
||||
var value = Buffer.from('')
|
||||
client.hset([hash, field, value], function (err, res) {
|
||||
assert.strictEqual(err, null)
|
||||
assert.strictEqual(res, 1)
|
||||
client.hset(hash, field, value, helper.isNumber(0, done))
|
||||
})
|
||||
})
|
||||
|
||||
client.hset(hash, field, value, helper.isNumber(1));
|
||||
client.hget([hash, field], helper.isString('', done));
|
||||
});
|
||||
it('warns if someone passed a array either as field or as value', function (done) {
|
||||
var hash = 'test hash'
|
||||
var field = 'array'
|
||||
// This would be converted to "array contents" but if you use more than one entry,
|
||||
// it'll result in e.g. "array contents,second content" and this is not supported and considered harmful
|
||||
var value = ['array contents']
|
||||
client.on('warning', function (msg) {
|
||||
assert.strictEqual(
|
||||
msg,
|
||||
'Deprecated: The HMSET command contains a argument of type Array.\n' +
|
||||
'This is converted to "array contents" by using .toString() now and will return an error from v.3.0 on.\n' +
|
||||
'Please handle this in your code to make sure everything works as you intended it to.'
|
||||
)
|
||||
done()
|
||||
})
|
||||
client.hmset(hash, field, value)
|
||||
})
|
||||
|
||||
it('handles empty key and value', function (done) {
|
||||
var field = new Buffer(0);
|
||||
var value = new Buffer(0);
|
||||
client.hset([hash, field, value], function (err, res) {
|
||||
assert.strictEqual(res, 1);
|
||||
client.hset(hash, field, value, helper.isNumber(0, 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 field1 = 'buffer'
|
||||
var value1 = Buffer.from('abcdefghij')
|
||||
var field2 = 'date'
|
||||
var value2 = new Date()
|
||||
|
||||
it('warns if someone passed a array either as field or as value', function (done) {
|
||||
var hash = 'test hash';
|
||||
var field = 'array';
|
||||
// This would be converted to "array contents" but if you use more than one entry,
|
||||
// it'll result in e.g. "array contents,second content" and this is not supported and considered harmful
|
||||
var value = ['array contents'];
|
||||
client.on('warning', function (msg) {
|
||||
assert.strictEqual(
|
||||
msg,
|
||||
'Deprecated: The HMSET command contains a argument of type Array.\n' +
|
||||
'This is converted to "array contents" by using .toString() now and will return an error from v.3.0 on.\n' +
|
||||
'Please handle this in your code to make sure everything works as you intended it to.'
|
||||
);
|
||||
done();
|
||||
});
|
||||
client.hmset(hash, field, value);
|
||||
});
|
||||
client.hmset(hash, field1, value1, field2, value2, helper.isString('OK', 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 field1 = 'buffer';
|
||||
var value1 = new Buffer('abcdefghij');
|
||||
var field2 = 'date';
|
||||
var value2 = new Date();
|
||||
it('does not error when a buffer and date are set as fields on the same hash', function (done) {
|
||||
var hash = 'test hash'
|
||||
var value1 = 'buffer'
|
||||
var field1 = Buffer.from('abcdefghij')
|
||||
var value2 = 'date'
|
||||
var field2 = new Date()
|
||||
|
||||
client.hmset(hash, field1, value1, field2, value2, helper.isString('OK', done));
|
||||
});
|
||||
client.hmset(hash, field1, value1, field2, value2, helper.isString('OK', done))
|
||||
})
|
||||
|
||||
it('does not error when a buffer and date are set as fields on the same hash', function (done) {
|
||||
var hash = 'test hash';
|
||||
var value1 = 'buffer';
|
||||
var field1 = new Buffer('abcdefghij');
|
||||
var value2 = 'date';
|
||||
var field2 = new Date();
|
||||
|
||||
client.hmset(hash, field1, value1, field2, value2, helper.isString('OK', done));
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,26 +1,22 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var assert = require('assert');
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var assert = require('assert')
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
|
||||
describe("The 'incr' method", function () {
|
||||
describe('The \'incr\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
describe('when connected and a value in Redis', function () {
|
||||
var client
|
||||
var key = 'ABOVE_SAFE_JAVASCRIPT_INTEGER'
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
|
||||
describe('when connected and a value in Redis', function () {
|
||||
|
||||
var client;
|
||||
var key = 'ABOVE_SAFE_JAVASCRIPT_INTEGER';
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
|
||||
/*
|
||||
/*
|
||||
Number.MAX_SAFE_INTEGER === Math.pow(2, 53) - 1 === 9007199254740991
|
||||
|
||||
9007199254740992 -> 9007199254740992
|
||||
@@ -31,45 +27,45 @@ describe("The 'incr' method", function () {
|
||||
9007199254740997 -> 9007199254740996
|
||||
...
|
||||
*/
|
||||
it('count above the safe integers as numbers', function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
// Set a value to the maximum safe allowed javascript number (2^53) - 1
|
||||
client.set(key, Number.MAX_SAFE_INTEGER, helper.isNotError());
|
||||
client.incr(key, helper.isNumber(Number.MAX_SAFE_INTEGER + 1));
|
||||
client.incr(key, helper.isNumber(Number.MAX_SAFE_INTEGER + 2));
|
||||
client.incr(key, helper.isNumber(Number.MAX_SAFE_INTEGER + 3));
|
||||
client.incr(key, helper.isNumber(Number.MAX_SAFE_INTEGER + 4));
|
||||
client.incr(key, helper.isNumber(Number.MAX_SAFE_INTEGER + 5));
|
||||
client.incr(key, function (err, res) {
|
||||
helper.isNumber(Number.MAX_SAFE_INTEGER + 6)(err, res);
|
||||
assert.strictEqual(typeof res, 'number');
|
||||
});
|
||||
client.incr(key, helper.isNumber(Number.MAX_SAFE_INTEGER + 7));
|
||||
client.incr(key, helper.isNumber(Number.MAX_SAFE_INTEGER + 8));
|
||||
client.incr(key, helper.isNumber(Number.MAX_SAFE_INTEGER + 9));
|
||||
client.incr(key, helper.isNumber(Number.MAX_SAFE_INTEGER + 10, done));
|
||||
});
|
||||
it('count above the safe integers as numbers', function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
// Set a value to the maximum safe allowed javascript number (2^53) - 1
|
||||
client.set(key, Number.MAX_SAFE_INTEGER, helper.isNotError())
|
||||
client.incr(key, helper.isNumber(Number.MAX_SAFE_INTEGER + 1))
|
||||
client.incr(key, helper.isNumber(Number.MAX_SAFE_INTEGER + 2))
|
||||
client.incr(key, helper.isNumber(Number.MAX_SAFE_INTEGER + 3))
|
||||
client.incr(key, helper.isNumber(Number.MAX_SAFE_INTEGER + 4))
|
||||
client.incr(key, helper.isNumber(Number.MAX_SAFE_INTEGER + 5))
|
||||
client.incr(key, function (err, res) {
|
||||
helper.isNumber(Number.MAX_SAFE_INTEGER + 6)(err, res)
|
||||
assert.strictEqual(typeof res, 'number')
|
||||
})
|
||||
client.incr(key, helper.isNumber(Number.MAX_SAFE_INTEGER + 7))
|
||||
client.incr(key, helper.isNumber(Number.MAX_SAFE_INTEGER + 8))
|
||||
client.incr(key, helper.isNumber(Number.MAX_SAFE_INTEGER + 9))
|
||||
client.incr(key, helper.isNumber(Number.MAX_SAFE_INTEGER + 10, done))
|
||||
})
|
||||
|
||||
it('count above the safe integers as strings', function (done) {
|
||||
args[2].stringNumbers = true;
|
||||
client = redis.createClient.apply(null, args);
|
||||
// Set a value to the maximum safe allowed javascript number (2^53)
|
||||
client.set(key, Number.MAX_SAFE_INTEGER, helper.isNotError());
|
||||
client.incr(key, helper.isString('9007199254740992'));
|
||||
client.incr(key, helper.isString('9007199254740993'));
|
||||
client.incr(key, helper.isString('9007199254740994'));
|
||||
client.incr(key, helper.isString('9007199254740995'));
|
||||
client.incr(key, helper.isString('9007199254740996'));
|
||||
client.incr(key, function (err, res) {
|
||||
helper.isString('9007199254740997')(err, res);
|
||||
assert.strictEqual(typeof res, 'string');
|
||||
});
|
||||
client.incr(key, helper.isString('9007199254740998'));
|
||||
client.incr(key, helper.isString('9007199254740999'));
|
||||
client.incr(key, helper.isString('9007199254741000'));
|
||||
client.incr(key, helper.isString('9007199254741001', done));
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
it('count above the safe integers as strings', function (done) {
|
||||
args[2].stringNumbers = true
|
||||
client = redis.createClient.apply(null, args)
|
||||
// Set a value to the maximum safe allowed javascript number (2^53)
|
||||
client.set(key, Number.MAX_SAFE_INTEGER, helper.isNotError())
|
||||
client.incr(key, helper.isString('9007199254740992'))
|
||||
client.incr(key, helper.isString('9007199254740993'))
|
||||
client.incr(key, helper.isString('9007199254740994'))
|
||||
client.incr(key, helper.isString('9007199254740995'))
|
||||
client.incr(key, helper.isString('9007199254740996'))
|
||||
client.incr(key, function (err, res) {
|
||||
helper.isString('9007199254740997')(err, res)
|
||||
assert.strictEqual(typeof res, 'string')
|
||||
})
|
||||
client.incr(key, helper.isString('9007199254740998'))
|
||||
client.incr(key, helper.isString('9007199254740999'))
|
||||
client.incr(key, helper.isString('9007199254741000'))
|
||||
client.incr(key, helper.isString('9007199254741001', done))
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,79 +1,78 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var assert = require('assert');
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var assert = require('assert')
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
|
||||
describe("The 'info' method", function () {
|
||||
describe('The \'info\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
var client
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.flushall(done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var client;
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.flushall(done);
|
||||
});
|
||||
});
|
||||
it('update serverInfo after a info command', function (done) {
|
||||
client.set('foo', 'bar')
|
||||
client.info()
|
||||
client.select(2, function () {
|
||||
assert.strictEqual(client.serverInfo.db2, undefined)
|
||||
})
|
||||
client.set('foo', 'bar')
|
||||
client.info()
|
||||
setTimeout(function () {
|
||||
assert.strictEqual(typeof client.serverInfo.db2, 'object')
|
||||
done()
|
||||
}, 30)
|
||||
})
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
it('works with optional section provided with and without callback', function (done) {
|
||||
client.set('foo', 'bar')
|
||||
client.info('keyspace')
|
||||
client.select(2, function () {
|
||||
assert.strictEqual(Object.keys(client.serverInfo).length, 2, 'Key length should be three')
|
||||
assert.strictEqual(typeof client.serverInfo.db0, 'object', 'db0 keyspace should be an object')
|
||||
})
|
||||
client.info(['keyspace'])
|
||||
client.set('foo', 'bar')
|
||||
client.info('all', function (err, res) {
|
||||
assert.strictEqual(err, null)
|
||||
assert(Object.keys(client.serverInfo).length > 3, 'Key length should be way above three')
|
||||
assert.strictEqual(typeof client.serverInfo.redis_version, 'string')
|
||||
assert.strictEqual(typeof client.serverInfo.db2, 'object')
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('update serverInfo after a info command', function (done) {
|
||||
client.set('foo', 'bar');
|
||||
client.info();
|
||||
client.select(2, function () {
|
||||
assert.strictEqual(client.serverInfo.db2, undefined);
|
||||
});
|
||||
client.set('foo', 'bar');
|
||||
client.info();
|
||||
setTimeout(function () {
|
||||
assert.strictEqual(typeof client.serverInfo.db2, 'object');
|
||||
done();
|
||||
}, 30);
|
||||
});
|
||||
it('check redis v.2.4 support', function (done) {
|
||||
var end = helper.callFuncAfter(done, 2)
|
||||
client.internalSendCommand = function (commandObj) {
|
||||
assert.strictEqual(commandObj.args.length, 0)
|
||||
assert.strictEqual(commandObj.command, 'info')
|
||||
end()
|
||||
}
|
||||
client.info()
|
||||
client.info(function () {})
|
||||
})
|
||||
|
||||
it('works with optional section provided with and without callback', function (done) {
|
||||
client.set('foo', 'bar');
|
||||
client.info('keyspace');
|
||||
client.select(2, function () {
|
||||
assert.strictEqual(Object.keys(client.serverInfo).length, 2, 'Key length should be three');
|
||||
assert.strictEqual(typeof client.serverInfo.db0, 'object', 'db0 keyspace should be an object');
|
||||
});
|
||||
client.info(['keyspace']);
|
||||
client.set('foo', 'bar');
|
||||
client.info('all', function (err, res) {
|
||||
assert(Object.keys(client.serverInfo).length > 3, 'Key length should be way above three');
|
||||
assert.strictEqual(typeof client.serverInfo.redis_version, 'string');
|
||||
assert.strictEqual(typeof client.serverInfo.db2, 'object');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('check redis v.2.4 support', function (done) {
|
||||
var end = helper.callFuncAfter(done, 2);
|
||||
client.internalSendCommand = function (commandObj) {
|
||||
assert.strictEqual(commandObj.args.length, 0);
|
||||
assert.strictEqual(commandObj.command, 'info');
|
||||
end();
|
||||
};
|
||||
client.info();
|
||||
client.info(function () {});
|
||||
});
|
||||
|
||||
it('emit error after a failure', function (done) {
|
||||
client.info();
|
||||
client.once('error', function (err) {
|
||||
assert.strictEqual(err.code, 'UNCERTAIN_STATE');
|
||||
assert.strictEqual(err.command, 'INFO');
|
||||
done();
|
||||
});
|
||||
client.stream.destroy();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
it('emit error after a failure', function (done) {
|
||||
client.info()
|
||||
client.once('error', function (err) {
|
||||
assert.strictEqual(err.code, 'UNCERTAIN_STATE')
|
||||
assert.strictEqual(err.command, 'INFO')
|
||||
done()
|
||||
})
|
||||
client.stream.destroy()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,69 +1,67 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var assert = require('assert');
|
||||
var config = require('../lib/config');
|
||||
var crypto = require('crypto');
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var assert = require('assert')
|
||||
var config = require('../lib/config')
|
||||
var crypto = require('crypto')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
|
||||
describe("The 'keys' method", function () {
|
||||
describe('The \'keys\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
var client
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.flushall(done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var client;
|
||||
it('returns matching keys', function (done) {
|
||||
client.mset(['test keys 1', 'test val 1', 'test keys 2', 'test val 2'], helper.isString('OK'))
|
||||
client.keys('test keys*', function (err, results) {
|
||||
assert.strictEqual(2, results.length)
|
||||
assert.ok(~results.indexOf('test keys 1'))
|
||||
assert.ok(~results.indexOf('test keys 2'))
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.flushall(done);
|
||||
});
|
||||
});
|
||||
it('handles a large packet size', function (done) {
|
||||
var keysValues = []
|
||||
|
||||
it('returns matching keys', function (done) {
|
||||
client.mset(['test keys 1', 'test val 1', 'test keys 2', 'test val 2'], helper.isString('OK'));
|
||||
client.keys('test keys*', function (err, results) {
|
||||
assert.strictEqual(2, results.length);
|
||||
assert.ok(~results.indexOf('test keys 1'));
|
||||
assert.ok(~results.indexOf('test keys 2'));
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
for (var i = 0; i < 200; i++) {
|
||||
var keyValue = [
|
||||
'multibulk:' + crypto.randomBytes(256).toString('hex'), // use long strings as keys to ensure generation of large packet
|
||||
'test val ' + i
|
||||
]
|
||||
keysValues.push(keyValue)
|
||||
}
|
||||
|
||||
it('handles a large packet size', function (done) {
|
||||
var keysValues = [];
|
||||
client.mset(keysValues.reduce(function (a, b) {
|
||||
return a.concat(b)
|
||||
}), helper.isString('OK'))
|
||||
|
||||
for (var i = 0; i < 200; i++) {
|
||||
var keyValue = [
|
||||
'multibulk:' + crypto.randomBytes(256).toString('hex'), // use long strings as keys to ensure generation of large packet
|
||||
'test val ' + i
|
||||
];
|
||||
keysValues.push(keyValue);
|
||||
}
|
||||
client.keys('multibulk:*', function (err, results) {
|
||||
assert.deepEqual(keysValues.map(function (val) {
|
||||
return val[0]
|
||||
}).sort(), results.sort())
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
|
||||
client.mset(keysValues.reduce(function (a, b) {
|
||||
return a.concat(b);
|
||||
}), helper.isString('OK'));
|
||||
it('handles an empty response', function (done) {
|
||||
client.keys(['users:*'], function (err, results) {
|
||||
assert.strictEqual(results.length, 0)
|
||||
assert.ok(Array.isArray(results))
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
|
||||
client.keys('multibulk:*', function (err, results) {
|
||||
assert.deepEqual(keysValues.map(function (val) {
|
||||
return val[0];
|
||||
}).sort(), results.sort());
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
|
||||
it('handles an empty response', function (done) {
|
||||
client.keys(['users:*'], function (err, results) {
|
||||
assert.strictEqual(results.length, 0);
|
||||
assert.ok(Array.isArray(results));
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,70 +1,68 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var assert = require('assert');
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var assert = require('assert')
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
|
||||
describe("The 'mget' method", function () {
|
||||
describe('The \'mget\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
var client
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('error', done)
|
||||
client.once('ready', function () {
|
||||
client.flushdb()
|
||||
client.mset(['mget keys 1', 'mget val 1', 'mget keys 2', 'mget val 2', 'mget keys 3', 'mget val 3'], done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var client;
|
||||
it('handles fetching multiple keys in argument form', function (done) {
|
||||
client.mset(['mget keys 1', 'mget val 1', 'mget keys 2', 'mget val 2', 'mget keys 3', 'mget val 3'], helper.isString('OK'))
|
||||
client.mget('mget keys 1', 'mget keys 2', 'mget keys 3', function (err, results) {
|
||||
assert.strictEqual(3, results.length)
|
||||
assert.strictEqual('mget val 1', results[0].toString())
|
||||
assert.strictEqual('mget val 2', results[1].toString())
|
||||
assert.strictEqual('mget val 3', results[2].toString())
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('error', done);
|
||||
client.once('ready', function () {
|
||||
client.flushdb();
|
||||
client.mset(['mget keys 1', 'mget val 1', 'mget keys 2', 'mget val 2', 'mget keys 3', 'mget val 3'], done);
|
||||
});
|
||||
});
|
||||
it('handles fetching multiple keys via an array', function (done) {
|
||||
client.mget(['mget keys 1', 'mget keys 2', 'mget keys 3'], function (err, results) {
|
||||
assert.strictEqual('mget val 1', results[0].toString())
|
||||
assert.strictEqual('mget val 2', results[1].toString())
|
||||
assert.strictEqual('mget val 3', results[2].toString())
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
|
||||
it('handles fetching multiple keys in argument form', function (done) {
|
||||
client.mset(['mget keys 1', 'mget val 1', 'mget keys 2', 'mget val 2', 'mget keys 3', 'mget val 3'], helper.isString('OK'));
|
||||
client.mget('mget keys 1', 'mget keys 2', 'mget keys 3', function (err, results) {
|
||||
assert.strictEqual(3, results.length);
|
||||
assert.strictEqual('mget val 1', results[0].toString());
|
||||
assert.strictEqual('mget val 2', results[1].toString());
|
||||
assert.strictEqual('mget val 3', results[2].toString());
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
it('handles fetching multiple keys, when some keys do not exist', function (done) {
|
||||
client.mget('mget keys 1', ['some random shit', 'mget keys 2', 'mget keys 3'], function (err, results) {
|
||||
assert.strictEqual(4, results.length)
|
||||
assert.strictEqual('mget val 1', results[0].toString())
|
||||
assert.strictEqual(null, results[1])
|
||||
assert.strictEqual('mget val 2', results[2].toString())
|
||||
assert.strictEqual('mget val 3', results[3].toString())
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
|
||||
it('handles fetching multiple keys via an array', function (done) {
|
||||
client.mget(['mget keys 1', 'mget keys 2', 'mget keys 3'], function (err, results) {
|
||||
assert.strictEqual('mget val 1', results[0].toString());
|
||||
assert.strictEqual('mget val 2', results[1].toString());
|
||||
assert.strictEqual('mget val 3', results[2].toString());
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
it('handles fetching multiple keys, when some keys do not exist promisified', function () {
|
||||
return client.mgetAsync('mget keys 1', ['some random shit', 'mget keys 2', 'mget keys 3']).then(function (results) {
|
||||
assert.strictEqual(4, results.length)
|
||||
assert.strictEqual('mget val 1', results[0].toString())
|
||||
assert.strictEqual(null, results[1])
|
||||
assert.strictEqual('mget val 2', results[2].toString())
|
||||
assert.strictEqual('mget val 3', results[3].toString())
|
||||
})
|
||||
})
|
||||
|
||||
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) {
|
||||
assert.strictEqual(4, results.length);
|
||||
assert.strictEqual('mget val 1', results[0].toString());
|
||||
assert.strictEqual(null, results[1]);
|
||||
assert.strictEqual('mget val 2', results[2].toString());
|
||||
assert.strictEqual('mget val 3', results[3].toString());
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
|
||||
it('handles fetching multiple keys, when some keys do not exist promisified', function () {
|
||||
return client.mgetAsync('mget keys 1', ['some random shit', 'mget keys 2', 'mget keys 3']).then(function (results) {
|
||||
assert.strictEqual(4, results.length);
|
||||
assert.strictEqual('mget val 1', results[0].toString());
|
||||
assert.strictEqual(null, results[1]);
|
||||
assert.strictEqual('mget val 2', results[2].toString());
|
||||
assert.strictEqual('mget val 3', results[3].toString());
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,215 +1,215 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var assert = require('assert');
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var utils = require('../../lib/utils');
|
||||
var redis = config.redis;
|
||||
var Buffer = require('safe-buffer').Buffer
|
||||
var assert = require('assert')
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var utils = require('../../lib/utils')
|
||||
var redis = config.redis
|
||||
|
||||
describe("The 'monitor' method", function () {
|
||||
describe('The \'monitor\' method', function () {
|
||||
helper.allTests(function (parser, ip, args) {
|
||||
var client
|
||||
|
||||
helper.allTests(function (parser, ip, args) {
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
|
||||
var client;
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('connect', function () {
|
||||
client.flushdb(done)
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
it('monitors commands on all redis clients and works in the correct order', function (done) {
|
||||
var monitorClient = redis.createClient.apply(null, args)
|
||||
var responses = [
|
||||
['mget', 'some', 'keys', 'foo', 'bar'],
|
||||
['set', 'json', '{"foo":"123","bar":"sdflkdfsjk","another":false}'],
|
||||
['eval', 'return redis.call(\'set\', \'sha\', \'test\')', '0'],
|
||||
['set', 'sha', 'test'],
|
||||
['get', 'baz'],
|
||||
['set', 'foo', 'bar" "s are " " good!"'],
|
||||
['mget', 'foo', 'baz'],
|
||||
['subscribe', 'foo', 'baz']
|
||||
]
|
||||
var end = helper.callFuncAfter(done, 5)
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('connect', function () {
|
||||
client.flushdb(done);
|
||||
});
|
||||
});
|
||||
monitorClient.set('foo', 'bar')
|
||||
monitorClient.flushdb()
|
||||
monitorClient.monitor(function (err, res) {
|
||||
assert.strictEqual(err, null)
|
||||
assert.strictEqual(res, 'OK')
|
||||
client.mget('some', 'keys', 'foo', 'bar')
|
||||
client.set('json', JSON.stringify({
|
||||
foo: '123',
|
||||
bar: 'sdflkdfsjk',
|
||||
another: false
|
||||
}))
|
||||
client.eval('return redis.call(\'set\', \'sha\', \'test\')', 0)
|
||||
monitorClient.get('baz', function (err, res) {
|
||||
assert.strictEqual(res, null)
|
||||
end(err)
|
||||
})
|
||||
monitorClient.set('foo', 'bar" "s are " " good!"', function (err, res) {
|
||||
assert.strictEqual(res, 'OK')
|
||||
end(err)
|
||||
})
|
||||
monitorClient.mget('foo', 'baz', function (err, res) {
|
||||
assert.strictEqual(res[0], 'bar" "s are " " good!"')
|
||||
assert.strictEqual(res[1], null)
|
||||
end(err)
|
||||
})
|
||||
monitorClient.subscribe('foo', 'baz', function (err, res) {
|
||||
// The return value might change in v.3
|
||||
// assert.strictEqual(res, 'baz');
|
||||
// TODO: Fix the return value of subscribe calls
|
||||
end(err)
|
||||
})
|
||||
})
|
||||
|
||||
it('monitors commands on all redis clients and works in the correct order', function (done) {
|
||||
var monitorClient = redis.createClient.apply(null, args);
|
||||
var responses = [
|
||||
['mget', 'some', 'keys', 'foo', 'bar'],
|
||||
['set', 'json', '{"foo":"123","bar":"sdflkdfsjk","another":false}'],
|
||||
['eval', "return redis.call('set', 'sha', 'test')", '0'],
|
||||
['set', 'sha', 'test'],
|
||||
['get', 'baz'],
|
||||
['set', 'foo', 'bar" "s are " " good!"'],
|
||||
['mget', 'foo', 'baz'],
|
||||
['subscribe', 'foo', 'baz']
|
||||
];
|
||||
var end = helper.callFuncAfter(done, 5);
|
||||
monitorClient.on('monitor', function (time, args, rawOutput) {
|
||||
assert.strictEqual(monitorClient.monitoring, true)
|
||||
assert.deepEqual(args, responses.shift())
|
||||
assert(utils.monitorRegex.test(rawOutput), rawOutput)
|
||||
if (responses.length === 0) {
|
||||
monitorClient.quit(end)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
monitorClient.set('foo', 'bar');
|
||||
monitorClient.flushdb();
|
||||
monitorClient.monitor(function (err, res) {
|
||||
assert.strictEqual(res, 'OK');
|
||||
client.mget('some', 'keys', 'foo', 'bar');
|
||||
client.set('json', JSON.stringify({
|
||||
foo: '123',
|
||||
bar: 'sdflkdfsjk',
|
||||
another: false
|
||||
}));
|
||||
client.eval("return redis.call('set', 'sha', 'test')", 0);
|
||||
monitorClient.get('baz', function (err, res) {
|
||||
assert.strictEqual(res, null);
|
||||
end(err);
|
||||
});
|
||||
monitorClient.set('foo', 'bar" "s are " " good!"', function (err, res) {
|
||||
assert.strictEqual(res, 'OK');
|
||||
end(err);
|
||||
});
|
||||
monitorClient.mget('foo', 'baz', function (err, res) {
|
||||
assert.strictEqual(res[0], 'bar" "s are " " good!"');
|
||||
assert.strictEqual(res[1], null);
|
||||
end(err);
|
||||
});
|
||||
monitorClient.subscribe('foo', 'baz', function (err, res) {
|
||||
// The return value might change in v.3
|
||||
// assert.strictEqual(res, 'baz');
|
||||
// TODO: Fix the return value of subscribe calls
|
||||
end(err);
|
||||
});
|
||||
});
|
||||
it('monitors returns strings in the rawOutput even with returnBuffers activated', function (done) {
|
||||
if (process.platform === 'win32') {
|
||||
this.skip()
|
||||
}
|
||||
var monitorClient = redis.createClient({
|
||||
returnBuffers: true,
|
||||
path: '/tmp/redis.sock'
|
||||
})
|
||||
|
||||
monitorClient.on('monitor', function (time, args, rawOutput) {
|
||||
assert.strictEqual(monitorClient.monitoring, true);
|
||||
assert.deepEqual(args, responses.shift());
|
||||
assert(utils.monitorRegex.test(rawOutput), rawOutput);
|
||||
if (responses.length === 0) {
|
||||
monitorClient.quit(end);
|
||||
}
|
||||
});
|
||||
});
|
||||
monitorClient.monitor(function (err, res) {
|
||||
assert.strictEqual(err, null)
|
||||
assert.strictEqual(monitorClient.monitoring, true)
|
||||
assert.strictEqual(res.inspect(), Buffer.from('OK').inspect())
|
||||
monitorClient.mget('hello', Buffer.from('world'))
|
||||
})
|
||||
|
||||
it('monitors returns strings in the rawOutput even with returnBuffers activated', function (done) {
|
||||
if (process.platform === 'win32') {
|
||||
this.skip();
|
||||
}
|
||||
var monitorClient = redis.createClient({
|
||||
returnBuffers: true,
|
||||
path: '/tmp/redis.sock'
|
||||
});
|
||||
monitorClient.on('monitor', function (time, args, rawOutput) {
|
||||
assert.strictEqual(typeof rawOutput, 'string')
|
||||
assert(utils.monitorRegex.test(rawOutput), rawOutput)
|
||||
assert.deepEqual(args, ['mget', 'hello', 'world'])
|
||||
// Quit immediately ends monitoring mode and therefore does not stream back the quit command
|
||||
monitorClient.quit(done)
|
||||
})
|
||||
})
|
||||
|
||||
monitorClient.monitor(function (err, res) {
|
||||
assert.strictEqual(monitorClient.monitoring, true);
|
||||
assert.strictEqual(res.inspect(), new Buffer('OK').inspect());
|
||||
monitorClient.mget('hello', new Buffer('world'));
|
||||
});
|
||||
it('monitors reconnects properly and works with the offline queue', function (done) {
|
||||
var called = false
|
||||
client.monitor(helper.isString('OK'))
|
||||
client.mget('hello', 'world')
|
||||
client.on('monitor', function (time, args, rawOutput) {
|
||||
assert.strictEqual(client.monitoring, true)
|
||||
assert(utils.monitorRegex.test(rawOutput), rawOutput)
|
||||
assert.deepEqual(args, ['mget', 'hello', 'world'])
|
||||
if (called) {
|
||||
// End after a reconnect
|
||||
return done()
|
||||
}
|
||||
client.stream.destroy()
|
||||
client.mget('hello', 'world')
|
||||
called = true
|
||||
})
|
||||
})
|
||||
|
||||
monitorClient.on('monitor', function (time, args, rawOutput) {
|
||||
assert.strictEqual(typeof rawOutput, 'string');
|
||||
assert(utils.monitorRegex.test(rawOutput), rawOutput);
|
||||
assert.deepEqual(args, ['mget', 'hello', 'world']);
|
||||
// Quit immediatly ends monitoring mode and therefore does not stream back the quit command
|
||||
monitorClient.quit(done);
|
||||
});
|
||||
});
|
||||
it('monitors reconnects properly and works with the offline queue in a batch statement', function (done) {
|
||||
var called = false
|
||||
var multi = client.batch()
|
||||
multi.monitor(helper.isString('OK'))
|
||||
multi.mget('hello', 'world')
|
||||
multi.exec(helper.isDeepEqual(['OK', [null, null]]))
|
||||
client.on('monitor', function (time, args, rawOutput) {
|
||||
assert.strictEqual(client.monitoring, true)
|
||||
assert(utils.monitorRegex.test(rawOutput), rawOutput)
|
||||
assert.deepEqual(args, ['mget', 'hello', 'world'])
|
||||
if (called) {
|
||||
// End after a reconnect
|
||||
return done()
|
||||
}
|
||||
client.stream.destroy()
|
||||
client.mget('hello', 'world')
|
||||
called = true
|
||||
})
|
||||
})
|
||||
|
||||
it('monitors reconnects properly and works with the offline queue', function (done) {
|
||||
var called = false;
|
||||
client.monitor(helper.isString('OK'));
|
||||
client.mget('hello', 'world');
|
||||
client.on('monitor', function (time, args, rawOutput) {
|
||||
assert.strictEqual(client.monitoring, true);
|
||||
assert(utils.monitorRegex.test(rawOutput), rawOutput);
|
||||
assert.deepEqual(args, ['mget', 'hello', 'world']);
|
||||
if (called) {
|
||||
// End after a reconnect
|
||||
return done();
|
||||
}
|
||||
client.stream.destroy();
|
||||
client.mget('hello', 'world');
|
||||
called = true;
|
||||
});
|
||||
});
|
||||
it('monitor activates even if the command could not be processed properly after a reconnect', function (done) {
|
||||
client.monitor(function (err, res) {
|
||||
assert.strictEqual(err.code, 'UNCERTAIN_STATE')
|
||||
})
|
||||
client.on('error', function () {}) // Ignore error here
|
||||
client.stream.destroy()
|
||||
var end = helper.callFuncAfter(done, 2)
|
||||
client.on('monitor', function (time, args, rawOutput) {
|
||||
assert.strictEqual(client.monitoring, true)
|
||||
end()
|
||||
})
|
||||
client.on('reconnecting', function () {
|
||||
client.get('foo', function (err, res) {
|
||||
assert(!err)
|
||||
assert.strictEqual(client.monitoring, true)
|
||||
end()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('monitors reconnects properly and works with the offline queue in a batch statement', function (done) {
|
||||
var called = false;
|
||||
var multi = client.batch();
|
||||
multi.monitor(helper.isString('OK'));
|
||||
multi.mget('hello', 'world');
|
||||
multi.exec(function (err, res) {
|
||||
assert.deepEqual(res, ['OK', [null, null]]);
|
||||
});
|
||||
client.on('monitor', function (time, args, rawOutput) {
|
||||
assert.strictEqual(client.monitoring, true);
|
||||
assert(utils.monitorRegex.test(rawOutput), rawOutput);
|
||||
assert.deepEqual(args, ['mget', 'hello', 'world']);
|
||||
if (called) {
|
||||
// End after a reconnect
|
||||
return done();
|
||||
}
|
||||
client.stream.destroy();
|
||||
client.mget('hello', 'world');
|
||||
called = true;
|
||||
});
|
||||
});
|
||||
|
||||
it('monitor activates even if the command could not be processed properly after a reconnect', function (done) {
|
||||
client.monitor(function (err, res) {
|
||||
assert.strictEqual(err.code, 'UNCERTAIN_STATE');
|
||||
});
|
||||
client.on('error', function (err) {}); // Ignore error here
|
||||
client.stream.destroy();
|
||||
var end = helper.callFuncAfter(done, 2);
|
||||
client.on('monitor', function (time, args, rawOutput) {
|
||||
assert.strictEqual(client.monitoring, true);
|
||||
end();
|
||||
});
|
||||
client.on('reconnecting', function () {
|
||||
client.get('foo', function (err, res) {
|
||||
assert(!err);
|
||||
assert.strictEqual(client.monitoring, true);
|
||||
end();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('monitors works in combination with the pub sub mode and the offline queue', function (done) {
|
||||
var responses = [
|
||||
['subscribe', '/foo', '/bar'],
|
||||
['unsubscribe', '/bar'],
|
||||
['get', 'foo'],
|
||||
['subscribe', '/foo'],
|
||||
['subscribe', 'baz'],
|
||||
['unsubscribe', 'baz'],
|
||||
['publish', '/foo', 'hello world']
|
||||
];
|
||||
var pub = redis.createClient();
|
||||
pub.on('ready', function () {
|
||||
client.monitor(function (err, res) {
|
||||
assert.strictEqual(res, 'OK');
|
||||
pub.get('foo', helper.isNull());
|
||||
});
|
||||
client.subscribe('/foo', '/bar');
|
||||
client.unsubscribe('/bar');
|
||||
setTimeout(function () {
|
||||
client.stream.destroy();
|
||||
client.once('ready', function () {
|
||||
pub.publish('/foo', 'hello world');
|
||||
});
|
||||
client.set('foo', 'bar', helper.isError());
|
||||
client.subscribe('baz');
|
||||
client.unsubscribe('baz');
|
||||
}, 150);
|
||||
var called = false;
|
||||
client.on('monitor', function (time, args, rawOutput) {
|
||||
assert.deepEqual(args, responses.shift());
|
||||
assert(utils.monitorRegex.test(rawOutput), rawOutput);
|
||||
if (responses.length === 0) {
|
||||
// The publish is called right after the reconnect and the monitor is called before the message is emitted.
|
||||
// Therefore we have to wait till the next tick
|
||||
process.nextTick(function () {
|
||||
assert(called);
|
||||
client.quit(done);
|
||||
pub.end(false);
|
||||
});
|
||||
}
|
||||
});
|
||||
client.on('message', function (channel, msg) {
|
||||
assert.strictEqual(channel, '/foo');
|
||||
assert.strictEqual(msg, 'hello world');
|
||||
called = true;
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
it('monitors works in combination with the pub sub mode and the offline queue', function (done) {
|
||||
var responses = [
|
||||
['subscribe', '/foo', '/bar'],
|
||||
['unsubscribe', '/bar'],
|
||||
['get', 'foo'],
|
||||
['subscribe', '/foo'],
|
||||
['subscribe', 'baz'],
|
||||
['unsubscribe', 'baz'],
|
||||
['publish', '/foo', 'hello world']
|
||||
]
|
||||
var pub = redis.createClient()
|
||||
pub.on('ready', function () {
|
||||
client.monitor(function (err, res) {
|
||||
assert.strictEqual(err, null)
|
||||
assert.strictEqual(res, 'OK')
|
||||
pub.get('foo', helper.isNull())
|
||||
})
|
||||
client.subscribe('/foo', '/bar')
|
||||
client.unsubscribe('/bar')
|
||||
setTimeout(function () {
|
||||
client.stream.destroy()
|
||||
client.once('ready', function () {
|
||||
pub.publish('/foo', 'hello world')
|
||||
})
|
||||
client.set('foo', 'bar', helper.isError())
|
||||
client.subscribe('baz')
|
||||
client.unsubscribe('baz')
|
||||
}, 150)
|
||||
var called = false
|
||||
client.on('monitor', function (time, args, rawOutput) {
|
||||
assert.deepEqual(args, responses.shift())
|
||||
assert(utils.monitorRegex.test(rawOutput), rawOutput)
|
||||
if (responses.length === 0) {
|
||||
// The publish is called right after the reconnect and the monitor is called before the message is emitted.
|
||||
// Therefore we have to wait till the next tick
|
||||
process.nextTick(function () {
|
||||
assert(called)
|
||||
client.quit(done)
|
||||
pub.end(false)
|
||||
})
|
||||
}
|
||||
})
|
||||
client.on('message', function (channel, msg) {
|
||||
assert.strictEqual(channel, '/foo')
|
||||
assert.strictEqual(msg, 'hello world')
|
||||
called = true
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,111 +1,108 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var assert = require('assert');
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var uuid = require('uuid');
|
||||
var assert = require('assert')
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
var uuid = require('uuid')
|
||||
|
||||
describe("The 'mset' method", function () {
|
||||
describe('The \'mset\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
var key, value, key2, value2
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
beforeEach(function () {
|
||||
key = uuid.v4()
|
||||
value = uuid.v4()
|
||||
key2 = uuid.v4()
|
||||
value2 = uuid.v4()
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var key, value, key2, value2;
|
||||
describe('when not connected', function () {
|
||||
var client
|
||||
|
||||
beforeEach(function () {
|
||||
key = uuid.v4();
|
||||
value = uuid.v4();
|
||||
key2 = uuid.v4();
|
||||
value2 = uuid.v4();
|
||||
});
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.quit()
|
||||
})
|
||||
client.on('end', done)
|
||||
})
|
||||
|
||||
describe('when not connected', function () {
|
||||
var client;
|
||||
it('reports an error', function (done) {
|
||||
client.mset(key, value, key2, value2, function (err, res) {
|
||||
assert(err.message.match(/The connection is already closed/))
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.quit();
|
||||
});
|
||||
client.on('end', done);
|
||||
});
|
||||
describe('when connected', function () {
|
||||
var client
|
||||
|
||||
it('reports an error', function (done) {
|
||||
client.mset(key, value, key2, value2, function (err, res) {
|
||||
assert(err.message.match(/The connection is already closed/));
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
describe('when connected', function () {
|
||||
var client;
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
done();
|
||||
});
|
||||
});
|
||||
describe('and a callback is specified', function () {
|
||||
describe('with valid parameters', function () {
|
||||
it('sets the value correctly', function (done) {
|
||||
client.mset(key, value, key2, value2, function (err) {
|
||||
if (err) {
|
||||
return done(err)
|
||||
}
|
||||
client.get(key, helper.isString(value))
|
||||
client.get(key2, helper.isString(value2, done))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
describe('with undefined \'key\' parameter and missing \'value\' parameter', function () {
|
||||
it('reports an error', function (done) {
|
||||
client.mset(undefined, function (err, res) {
|
||||
helper.isError()(err, null)
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('and a callback is specified', function () {
|
||||
describe('with valid parameters', function () {
|
||||
it('sets the value correctly', function (done) {
|
||||
client.mset(key, value, key2, value2, function (err) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
client.get(key, helper.isString(value));
|
||||
client.get(key2, helper.isString(value2, done));
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('and no callback is specified', function () {
|
||||
describe('with valid parameters', function () {
|
||||
it('sets the value correctly', function (done) {
|
||||
client.mset(key, value2, key2, value)
|
||||
client.get(key, helper.isString(value2))
|
||||
client.get(key2, helper.isString(value, done))
|
||||
})
|
||||
|
||||
describe("with undefined 'key' parameter and missing 'value' parameter", function () {
|
||||
it('reports an error', function (done) {
|
||||
client.mset(undefined, function (err, res) {
|
||||
helper.isError()(err, null);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
it('sets the value correctly with array syntax', function (done) {
|
||||
client.mset([key, value2, key2, value])
|
||||
client.get(key, helper.isString(value2))
|
||||
client.get(key2, helper.isString(value, done))
|
||||
})
|
||||
})
|
||||
|
||||
});
|
||||
describe('with undefined \'key\' and missing \'value\' parameter', function () {
|
||||
// this behavior is different from the 'set' behavior.
|
||||
it('emits an error', function (done) {
|
||||
client.on('error', function (err) {
|
||||
assert.strictEqual(err.message, 'ERR wrong number of arguments for \'mset\' command')
|
||||
assert.strictEqual(err.name, 'ReplyError')
|
||||
done()
|
||||
})
|
||||
|
||||
describe('and no callback is specified', function () {
|
||||
describe('with valid parameters', function () {
|
||||
it('sets the value correctly', function (done) {
|
||||
client.mset(key, value2, key2, value);
|
||||
client.get(key, helper.isString(value2));
|
||||
client.get(key2, helper.isString(value, done));
|
||||
});
|
||||
|
||||
it('sets the value correctly with array syntax', function (done) {
|
||||
client.mset([key, value2, key2, value]);
|
||||
client.get(key, helper.isString(value2));
|
||||
client.get(key2, helper.isString(value, done));
|
||||
});
|
||||
});
|
||||
|
||||
describe("with undefined 'key' and missing 'value' parameter", function () {
|
||||
// this behavior is different from the 'set' behavior.
|
||||
it('emits an error', function (done) {
|
||||
client.on('error', function (err) {
|
||||
assert.strictEqual(err.message, "ERR wrong number of arguments for 'mset' command");
|
||||
assert.strictEqual(err.name, 'ReplyError');
|
||||
done();
|
||||
});
|
||||
|
||||
client.mset();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
client.mset()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,38 +1,36 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
|
||||
describe("The 'msetnx' method", function () {
|
||||
describe('The \'msetnx\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
var client
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var client;
|
||||
it('if any keys exist entire operation fails', function (done) {
|
||||
client.mset(['mset1', 'val1', 'mset2', 'val2', 'mset3', 'val3'], helper.isString('OK'))
|
||||
client.msetnx(['mset3', 'val3', 'mset4', 'val4'], helper.isNumber(0))
|
||||
client.exists(['mset4'], helper.isNumber(0, done))
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done);
|
||||
});
|
||||
});
|
||||
it('sets multiple keys if all keys are not set', function (done) {
|
||||
client.msetnx(['mset3', 'val3', 'mset4', 'val4'], helper.isNumber(1))
|
||||
client.exists(['mset3'], helper.isNumber(1))
|
||||
client.exists(['mset3'], helper.isNumber(1, done))
|
||||
})
|
||||
|
||||
it('if any keys exist entire operation fails', function (done) {
|
||||
client.mset(['mset1', 'val1', 'mset2', 'val2', 'mset3', 'val3'], helper.isString('OK'));
|
||||
client.msetnx(['mset3', 'val3', 'mset4', 'val4'], helper.isNumber(0));
|
||||
client.exists(['mset4'], helper.isNumber(0, done));
|
||||
});
|
||||
|
||||
it('sets multiple keys if all keys are not set', function (done) {
|
||||
client.msetnx(['mset3', 'val3', 'mset4', 'val4'], helper.isNumber(1));
|
||||
client.exists(['mset3'], helper.isNumber(1));
|
||||
client.exists(['mset3'], helper.isNumber(1, done));
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,35 +1,33 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var assert = require('assert');
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var assert = require('assert')
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
|
||||
describe("The 'randomkey' method", function () {
|
||||
describe('The \'randomkey\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
var client
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var client;
|
||||
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.randomkey([], function (err, results) {
|
||||
assert.strictEqual(true, /test keys.+/.test(results))
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done);
|
||||
});
|
||||
});
|
||||
|
||||
it('returns a random key', function (done) {
|
||||
client.mset(['test keys 1', 'test val 1', 'test keys 2', 'test val 2'], helper.isString('OK'));
|
||||
client.randomkey([], function (err, results) {
|
||||
assert.strictEqual(true, /test keys.+/.test(results));
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,38 +1,36 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
|
||||
describe("The 'rename' method", function () {
|
||||
describe('The \'rename\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
var client
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var client;
|
||||
it('populates the new key', function (done) {
|
||||
client.set(['foo', 'bar'], helper.isString('OK'))
|
||||
client.rename(['foo', 'new foo'], helper.isString('OK'))
|
||||
client.exists(['new foo'], helper.isNumber(1, done))
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done);
|
||||
});
|
||||
});
|
||||
it('removes the old key', function (done) {
|
||||
client.set(['foo', 'bar'], helper.isString('OK'))
|
||||
client.rename(['foo', 'new foo'], helper.isString('OK'))
|
||||
client.exists(['foo'], helper.isNumber(0, done))
|
||||
})
|
||||
|
||||
it('populates the new key', function (done) {
|
||||
client.set(['foo', 'bar'], helper.isString('OK'));
|
||||
client.rename(['foo', 'new foo'], helper.isString('OK'));
|
||||
client.exists(['new foo'], helper.isNumber(1, done));
|
||||
});
|
||||
|
||||
it('removes the old key', function (done) {
|
||||
client.set(['foo', 'bar'], helper.isString('OK'));
|
||||
client.rename(['foo', 'new foo'], helper.isString('OK'));
|
||||
client.exists(['foo'], helper.isNumber(0, done));
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,41 +1,39 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
|
||||
describe("The 'renamenx' method", function () {
|
||||
describe('The \'renamenx\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
var client
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var client;
|
||||
it('renames the key if target does not yet exist', function (done) {
|
||||
client.set('foo', 'bar', helper.isString('OK'))
|
||||
client.renamenx('foo', 'foo2', helper.isNumber(1))
|
||||
client.exists('foo', helper.isNumber(0))
|
||||
client.exists(['foo2'], helper.isNumber(1, done))
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done);
|
||||
});
|
||||
});
|
||||
it('does not rename the key if the target exists', function (done) {
|
||||
client.set('foo', 'bar', helper.isString('OK'))
|
||||
client.set('foo2', 'apple', helper.isString('OK'))
|
||||
client.renamenx('foo', 'foo2', helper.isNumber(0))
|
||||
client.exists('foo', helper.isNumber(1))
|
||||
client.exists(['foo2'], helper.isNumber(1, done))
|
||||
})
|
||||
|
||||
it('renames the key if target does not yet exist', function (done) {
|
||||
client.set('foo', 'bar', helper.isString('OK'));
|
||||
client.renamenx('foo', 'foo2', helper.isNumber(1));
|
||||
client.exists('foo', helper.isNumber(0));
|
||||
client.exists(['foo2'], helper.isNumber(1, done));
|
||||
});
|
||||
|
||||
it('does not rename the key if the target exists', function (done) {
|
||||
client.set('foo', 'bar', helper.isString('OK'));
|
||||
client.set('foo2', 'apple', helper.isString('OK'));
|
||||
client.renamenx('foo', 'foo2', helper.isNumber(0));
|
||||
client.exists('foo', helper.isNumber(1));
|
||||
client.exists(['foo2'], helper.isNumber(1, done));
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,36 +1,34 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var assert = require('assert');
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
var assert = require('assert')
|
||||
|
||||
describe("The 'rpush' command", function () {
|
||||
describe('The \'rpush\' command', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
var client
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var client;
|
||||
it('inserts multiple values at a time into a list', function (done) {
|
||||
client.rpush('test', ['list key', 'should be a list'])
|
||||
client.lrange('test', 0, -1, function (err, res) {
|
||||
assert.strictEqual(res[0], 'list key')
|
||||
assert.strictEqual(res[1], 'should be a list')
|
||||
done(err)
|
||||
})
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done);
|
||||
});
|
||||
});
|
||||
|
||||
it('inserts multiple values at a time into a list', function (done) {
|
||||
client.rpush('test', ['list key', 'should be a list']);
|
||||
client.lrange('test', 0, -1, function (err, res) {
|
||||
assert.equal(res[0], 'list key');
|
||||
assert.equal(res[1], 'should be a list');
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,62 +1,60 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var assert = require('assert');
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var assert = require('assert')
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
|
||||
describe("The 'sadd' method", function () {
|
||||
describe('The \'sadd\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
var client
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var client;
|
||||
it('allows a single value to be added to the set', function (done) {
|
||||
client.sadd('set0', 'member0', helper.isNumber(1))
|
||||
client.smembers('set0', function (err, res) {
|
||||
assert.ok(~res.indexOf('member0'))
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done);
|
||||
});
|
||||
});
|
||||
it('does not add the same value to the set twice', function (done) {
|
||||
client.sadd('set0', 'member0', helper.isNumber(1))
|
||||
client.sadd('set0', 'member0', helper.isNumber(0, done))
|
||||
})
|
||||
|
||||
it('allows a single value to be added to the set', function (done) {
|
||||
client.sadd('set0', 'member0', helper.isNumber(1));
|
||||
client.smembers('set0', function (err, res) {
|
||||
assert.ok(~res.indexOf('member0'));
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
it('allows multiple values to be added to the set', function (done) {
|
||||
client.sadd('set0', ['member0', 'member1', 'member2'], helper.isNumber(3))
|
||||
client.smembers('set0', function (err, res) {
|
||||
assert.strictEqual(res.length, 3)
|
||||
assert.ok(~res.indexOf('member0'))
|
||||
assert.ok(~res.indexOf('member1'))
|
||||
assert.ok(~res.indexOf('member2'))
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
|
||||
it('does not add the same value to the set twice', function (done) {
|
||||
client.sadd('set0', 'member0', helper.isNumber(1));
|
||||
client.sadd('set0', 'member0', helper.isNumber(0, 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.smembers('set0', function (err, res) {
|
||||
assert.strictEqual(res.length, 3)
|
||||
assert.ok(~res.indexOf('member0'))
|
||||
assert.ok(~res.indexOf('member1'))
|
||||
assert.ok(~res.indexOf('member2'))
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
|
||||
it('allows multiple values to be added to the set', function (done) {
|
||||
client.sadd('set0', ['member0', 'member1', 'member2'], helper.isNumber(3));
|
||||
client.smembers('set0', function (err, res) {
|
||||
assert.strictEqual(res.length, 3);
|
||||
assert.ok(~res.indexOf('member0'));
|
||||
assert.ok(~res.indexOf('member1'));
|
||||
assert.ok(~res.indexOf('member2'));
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
|
||||
it('allows multiple values to be added to the set with a different syntax', function (done) {
|
||||
client.sadd(['set0', 'member0', 'member1', 'member2'], helper.isNumber(3));
|
||||
client.smembers('set0', function (err, res) {
|
||||
assert.strictEqual(res.length, 3);
|
||||
assert.ok(~res.indexOf('member0'));
|
||||
assert.ok(~res.indexOf('member1'));
|
||||
assert.ok(~res.indexOf('member2'));
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,31 +1,29 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
|
||||
describe("The 'scard' method", function () {
|
||||
describe('The \'scard\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
var client
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var client;
|
||||
it('returns the number of values in a set', function (done) {
|
||||
client.sadd('foo', [1, 2, 3], helper.isNumber(3))
|
||||
client.scard('foo', helper.isNumber(3, done))
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done);
|
||||
});
|
||||
});
|
||||
|
||||
it('returns the number of values in a set', function (done) {
|
||||
client.sadd('foo', [1, 2, 3], helper.isNumber(3));
|
||||
client.scard('foo', helper.isNumber(3, done));
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,55 +1,44 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var assert = require('assert');
|
||||
var config = require('../lib/config');
|
||||
var crypto = require('crypto');
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var config = require('../lib/config')
|
||||
var crypto = require('crypto')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
|
||||
describe("The 'script' method", function () {
|
||||
describe('The \'script\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
var command = 'return 99'
|
||||
var commandSha = crypto.createHash('sha1').update(command).digest('hex')
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
var command = 'return 99';
|
||||
var commandSha = crypto.createHash('sha1').update(command).digest('hex');
|
||||
describe('using ' + ip, function () {
|
||||
var client
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var client;
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done)
|
||||
})
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done);
|
||||
});
|
||||
});
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
it('loads script with client.script(\'load\')', function (done) {
|
||||
client.script('load', command, helper.isString(commandSha, done))
|
||||
})
|
||||
|
||||
it("loads script with client.script('load')", function (done) {
|
||||
client.script('load', command, function (err, result) {
|
||||
assert.strictEqual(result, commandSha);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
it('allows a loaded script to be evaluated', function (done) {
|
||||
client.evalsha(commandSha, 0, helper.isNumber(99, done))
|
||||
})
|
||||
|
||||
it('allows a loaded script to be evaluated', function (done) {
|
||||
client.evalsha(commandSha, 0, helper.isNumber(99, done));
|
||||
});
|
||||
it('allows a script to be loaded as part of a chained transaction', function (done) {
|
||||
client.multi().script('load', command).exec(helper.isDeepEqual([commandSha], 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) {
|
||||
assert.strictEqual(result[0], commandSha);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
|
||||
it("allows a script to be loaded using a transaction's array syntax", function (done) {
|
||||
client.multi([['script', 'load', command]]).exec(function (err, result) {
|
||||
assert.strictEqual(result[0], commandSha);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
it('allows a script to be loaded using a transaction\'s array syntax', function (done) {
|
||||
client.multi([['script', 'load', command]]).exec(helper.isDeepEqual([commandSha], done))
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,47 +1,45 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var assert = require('assert');
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var assert = require('assert')
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
|
||||
describe("The 'sdiff' method", function () {
|
||||
describe('The \'sdiff\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
var client
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var client;
|
||||
it('returns set difference', function (done) {
|
||||
client.sadd('foo', 'x', helper.isNumber(1))
|
||||
client.sadd('foo', ['a'], helper.isNumber(1))
|
||||
client.sadd('foo', 'b', helper.isNumber(1))
|
||||
client.sadd(['foo', 'c'], helper.isNumber(1))
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done);
|
||||
});
|
||||
});
|
||||
client.sadd(['bar', 'c', helper.isNumber(1)])
|
||||
|
||||
it('returns set difference', function (done) {
|
||||
client.sadd('foo', 'x', helper.isNumber(1));
|
||||
client.sadd('foo', ['a'], helper.isNumber(1));
|
||||
client.sadd('foo', 'b', helper.isNumber(1));
|
||||
client.sadd(['foo', 'c'], helper.isNumber(1));
|
||||
client.sadd('baz', 'a', helper.isNumber(1))
|
||||
client.sadd('baz', 'd', helper.isNumber(1))
|
||||
|
||||
client.sadd(['bar', 'c', helper.isNumber(1)]);
|
||||
client.sdiff('foo', 'bar', 'baz', function (err, values) {
|
||||
values.sort()
|
||||
assert.strictEqual(values.length, 2)
|
||||
assert.strictEqual(values[0], 'b')
|
||||
assert.strictEqual(values[1], 'x')
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
|
||||
client.sadd('baz', 'a', helper.isNumber(1));
|
||||
client.sadd('baz', 'd', helper.isNumber(1));
|
||||
|
||||
client.sdiff('foo', 'bar', 'baz', function (err, values) {
|
||||
values.sort();
|
||||
assert.equal(values.length, 2);
|
||||
assert.equal(values[0], 'b');
|
||||
assert.equal(values[1], 'x');
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,47 +1,45 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var assert = require('assert');
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var assert = require('assert')
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
|
||||
describe("The 'sdiffstore' method", function () {
|
||||
describe('The \'sdiffstore\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
var client
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var client;
|
||||
it('calculates set difference ands stores it in a key', function (done) {
|
||||
client.sadd('foo', 'x', helper.isNumber(1))
|
||||
client.sadd('foo', 'a', helper.isNumber(1))
|
||||
client.sadd('foo', 'b', helper.isNumber(1))
|
||||
client.sadd('foo', 'c', helper.isNumber(1))
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done);
|
||||
});
|
||||
});
|
||||
client.sadd('bar', 'c', helper.isNumber(1))
|
||||
|
||||
it('calculates set difference ands stores it in a key', function (done) {
|
||||
client.sadd('foo', 'x', helper.isNumber(1));
|
||||
client.sadd('foo', 'a', helper.isNumber(1));
|
||||
client.sadd('foo', 'b', helper.isNumber(1));
|
||||
client.sadd('foo', 'c', helper.isNumber(1));
|
||||
client.sadd('baz', 'a', helper.isNumber(1))
|
||||
client.sadd('baz', 'd', helper.isNumber(1))
|
||||
|
||||
client.sadd('bar', 'c', helper.isNumber(1));
|
||||
client.sdiffstore('quux', 'foo', 'bar', 'baz', helper.isNumber(2))
|
||||
|
||||
client.sadd('baz', 'a', helper.isNumber(1));
|
||||
client.sadd('baz', 'd', helper.isNumber(1));
|
||||
client.smembers('quux', function (err, values) {
|
||||
var members = values.sort()
|
||||
assert.deepEqual(members, [ 'b', 'x' ])
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
|
||||
client.sdiffstore('quux', 'foo', 'bar', 'baz', helper.isNumber(2));
|
||||
|
||||
client.smembers('quux', function (err, values) {
|
||||
var members = values.sort();
|
||||
assert.deepEqual(members, [ 'b', 'x' ]);
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,126 +1,124 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var assert = require('assert');
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var assert = require('assert')
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
|
||||
describe("The 'select' method", function () {
|
||||
describe('The \'select\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
describe('when not connected', function () {
|
||||
var client
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.quit()
|
||||
})
|
||||
client.on('end', done)
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
describe('when not connected', function () {
|
||||
var client;
|
||||
it('returns an error if redis is not connected', function (done) {
|
||||
var buffering = client.select(1, function (err, res) {
|
||||
assert(err.message.match(/The connection is already closed/))
|
||||
done()
|
||||
})
|
||||
assert(typeof buffering === 'boolean')
|
||||
})
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.quit();
|
||||
});
|
||||
client.on('end', done);
|
||||
});
|
||||
describe('when connected', function () {
|
||||
var client
|
||||
|
||||
it('returns an error if redis is not connected', function (done) {
|
||||
var buffering = client.select(1, function (err, res) {
|
||||
assert(err.message.match(/The connection is already closed/));
|
||||
done();
|
||||
});
|
||||
assert(typeof buffering === 'boolean');
|
||||
});
|
||||
});
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when connected', function () {
|
||||
var client;
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done);
|
||||
});
|
||||
});
|
||||
it('changes the database and calls the callback', function (done) {
|
||||
// default value of null means database 0 will be used.
|
||||
assert.strictEqual(client.selectedDb, undefined, 'default db should be undefined')
|
||||
var buffering = client.select(1, function (err, res) {
|
||||
helper.isNotError()(err, res)
|
||||
assert.strictEqual(client.selectedDb, 1, 'db should be 1 after select')
|
||||
done()
|
||||
})
|
||||
assert(typeof buffering === 'boolean')
|
||||
})
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
describe('and a callback is specified', function () {
|
||||
describe('with a valid db index', function () {
|
||||
it('selects the appropriate database', function (done) {
|
||||
assert.strictEqual(client.selectedDb, undefined, 'default db should be undefined')
|
||||
client.select(1, function (err) {
|
||||
assert.strictEqual(err, null)
|
||||
assert.strictEqual(client.selectedDb, 1, 'we should have selected the new valid DB')
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('changes the database and calls the callback', function (done) {
|
||||
// default value of null means database 0 will be used.
|
||||
assert.strictEqual(client.selectedDb, undefined, 'default db should be undefined');
|
||||
var buffering = client.select(1, function (err, res) {
|
||||
helper.isNotError()(err, res);
|
||||
assert.strictEqual(client.selectedDb, 1, 'db should be 1 after select');
|
||||
done();
|
||||
});
|
||||
assert(typeof buffering === 'boolean');
|
||||
});
|
||||
describe('with an invalid db index', function () {
|
||||
it('returns an error', function (done) {
|
||||
assert.strictEqual(client.selectedDb, undefined, 'default db should be undefined')
|
||||
client.select(9999, function (err) {
|
||||
assert.strictEqual(err.code, 'ERR')
|
||||
assert.strictEqual(err.message, 'ERR invalid DB index')
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('and a callback is specified', function () {
|
||||
describe('with a valid db index', function () {
|
||||
it('selects the appropriate database', function (done) {
|
||||
assert.strictEqual(client.selectedDb, undefined, 'default db should be undefined');
|
||||
client.select(1, function (err) {
|
||||
assert.equal(err, null);
|
||||
assert.equal(client.selectedDb, 1, 'we should have selected the new valid DB');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('and no callback is specified', function () {
|
||||
describe('with a valid db index', function () {
|
||||
it('selects the appropriate database', function (done) {
|
||||
assert.strictEqual(client.selectedDb, undefined, 'default db should be undefined')
|
||||
client.select(1)
|
||||
setTimeout(function () {
|
||||
assert.strictEqual(client.selectedDb, 1, 'we should have selected the new valid DB')
|
||||
done()
|
||||
}, 25)
|
||||
})
|
||||
})
|
||||
|
||||
describe('with an invalid db index', function () {
|
||||
it('returns an error', function (done) {
|
||||
assert.strictEqual(client.selectedDb, undefined, 'default db should be undefined');
|
||||
client.select(9999, function (err) {
|
||||
assert.equal(err.code, 'ERR');
|
||||
assert.equal(err.message, 'ERR invalid DB index');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('with an invalid db index', function () {
|
||||
it('emits an error when callback not provided', function (done) {
|
||||
assert.strictEqual(client.selectedDb, undefined, 'default db should be undefined')
|
||||
|
||||
describe('and no callback is specified', function () {
|
||||
describe('with a valid db index', function () {
|
||||
it('selects the appropriate database', function (done) {
|
||||
assert.strictEqual(client.selectedDb, undefined, 'default db should be undefined');
|
||||
client.select(1);
|
||||
setTimeout(function () {
|
||||
assert.equal(client.selectedDb, 1, 'we should have selected the new valid DB');
|
||||
done();
|
||||
}, 25);
|
||||
});
|
||||
});
|
||||
client.on('error', function (err) {
|
||||
assert.strictEqual(err.command, 'SELECT')
|
||||
assert.strictEqual(err.message, 'ERR invalid DB index')
|
||||
done()
|
||||
})
|
||||
|
||||
describe('with an invalid db index', function () {
|
||||
it('emits an error when callback not provided', function (done) {
|
||||
assert.strictEqual(client.selectedDb, undefined, 'default db should be undefined');
|
||||
client.select(9999)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
client.on('error', function (err) {
|
||||
assert.strictEqual(err.command, 'SELECT');
|
||||
assert.equal(err.message, 'ERR invalid DB index');
|
||||
done();
|
||||
});
|
||||
|
||||
client.select(9999);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('reconnection occurs', function () {
|
||||
it('selects the appropriate database after a reconnect', function (done) {
|
||||
assert.strictEqual(client.selectedDb, undefined, 'default db should be undefined');
|
||||
client.select(3);
|
||||
client.set('foo', 'bar', function () {
|
||||
client.stream.destroy();
|
||||
});
|
||||
client.once('ready', function () {
|
||||
assert.strictEqual(client.selectedDb, 3);
|
||||
assert(typeof client.serverInfo.db3 === 'object');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('reconnection occurs', function () {
|
||||
it('selects the appropriate database after a reconnect', function (done) {
|
||||
assert.strictEqual(client.selectedDb, undefined, 'default db should be undefined')
|
||||
client.select(3)
|
||||
client.set('foo', 'bar', function () {
|
||||
client.stream.destroy()
|
||||
})
|
||||
client.once('ready', function () {
|
||||
assert.strictEqual(client.selectedDb, 3)
|
||||
assert(typeof client.serverInfo.db3 === 'object')
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,170 +1,168 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var assert = require('assert');
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var uuid = require('uuid');
|
||||
var assert = require('assert')
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
var uuid = require('uuid')
|
||||
|
||||
describe("The 'set' method", function () {
|
||||
describe('The \'set\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
var key, value
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
beforeEach(function () {
|
||||
key = uuid.v4()
|
||||
value = uuid.v4()
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var key, value;
|
||||
describe('when not connected', function () {
|
||||
var client
|
||||
|
||||
beforeEach(function () {
|
||||
key = uuid.v4();
|
||||
value = uuid.v4();
|
||||
});
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.quit()
|
||||
})
|
||||
client.on('end', done)
|
||||
})
|
||||
|
||||
describe('when not connected', function () {
|
||||
var client;
|
||||
it('reports an error', function (done) {
|
||||
client.set(key, value, function (err, res) {
|
||||
assert(err.message.match(/The connection is already closed/))
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.quit();
|
||||
});
|
||||
client.on('end', done);
|
||||
});
|
||||
describe('when connected', function () {
|
||||
var client
|
||||
|
||||
it('reports an error', function (done) {
|
||||
client.set(key, value, function (err, res) {
|
||||
assert(err.message.match(/The connection is already closed/));
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when connected', function () {
|
||||
var client;
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done);
|
||||
});
|
||||
});
|
||||
describe('and a callback is specified', function () {
|
||||
describe('with valid parameters', function () {
|
||||
it('sets the value correctly', function (done) {
|
||||
client.set(key, value, function (err, res) {
|
||||
helper.isNotError()(err, res)
|
||||
client.get(key, function (err, res) {
|
||||
helper.isString(value)(err, res)
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
it('set expire date in seconds', function (done) {
|
||||
client.set('foo', 'bar', 'ex', 10, helper.isString('OK'))
|
||||
client.pttl('foo', function (err, res) {
|
||||
assert(res >= 10000 - 50) // Max 50 ms should have passed
|
||||
assert(res <= 10000) // Max possible should be 10.000
|
||||
done(err)
|
||||
})
|
||||
})
|
||||
|
||||
describe('and a callback is specified', function () {
|
||||
describe('with valid parameters', function () {
|
||||
it('sets the value correctly', function (done) {
|
||||
client.set(key, value, function (err, res) {
|
||||
helper.isNotError()(err, res);
|
||||
client.get(key, function (err, res) {
|
||||
helper.isString(value)(err, res);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
it('set expire date in milliseconds', function (done) {
|
||||
client.set('foo', 'bar', 'px', 100, helper.isString('OK'))
|
||||
client.pttl('foo', function (err, res) {
|
||||
assert(res >= 50) // Max 50 ms should have passed
|
||||
assert(res <= 100) // Max possible should be 100
|
||||
done(err)
|
||||
})
|
||||
})
|
||||
|
||||
it('set expire date in seconds', function (done) {
|
||||
client.set('foo', 'bar', 'ex', 10, helper.isString('OK'));
|
||||
client.pttl('foo', function (err, res) {
|
||||
assert(res >= 10000 - 50); // Max 50 ms should have passed
|
||||
assert(res <= 10000); // Max possible should be 10.000
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
it('only set the key if (not) already set', function (done) {
|
||||
client.set('foo', 'bar', 'NX', helper.isString('OK'))
|
||||
client.set('foo', 'bar', 'nx', helper.isNull())
|
||||
client.set('foo', 'bar', 'EX', '10', 'XX', helper.isString('OK'))
|
||||
client.ttl('foo', function (err, res) {
|
||||
assert(res >= 9) // Min 9s should be left
|
||||
assert(res <= 10) // Max 10s should be left
|
||||
done(err)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('set expire date in milliseconds', function (done) {
|
||||
client.set('foo', 'bar', 'px', 100, helper.isString('OK'));
|
||||
client.pttl('foo', function (err, res) {
|
||||
assert(res >= 50); // Max 50 ms should have passed
|
||||
assert(res <= 100); // Max possible should be 100
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
describe('reports an error with invalid parameters', function () {
|
||||
it('undefined \'key\' and missing \'value\' parameter', function (done) {
|
||||
client.set(undefined, function (err, res) {
|
||||
helper.isError()(err, null)
|
||||
assert.strictEqual(err.command, 'SET')
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('only set the key if (not) already set', function (done) {
|
||||
client.set('foo', 'bar', 'NX', helper.isString('OK'));
|
||||
client.set('foo', 'bar', 'nx', helper.isNull());
|
||||
client.set('foo', 'bar', 'EX', '10', 'XX', helper.isString('OK'));
|
||||
client.ttl('foo', function (err, res) {
|
||||
assert(res >= 9); // Min 9s should be left
|
||||
assert(res <= 10); // Max 10s should be left
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
it('empty array as second parameter', function (done) {
|
||||
client.set('foo', [], function (err, res) {
|
||||
assert.strictEqual(err.message, 'ERR wrong number of arguments for \'set\' command')
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('reports an error with invalid parameters', function () {
|
||||
it("undefined 'key' and missing 'value' parameter", function (done) {
|
||||
client.set(undefined, function (err, res) {
|
||||
helper.isError()(err, null);
|
||||
assert.equal(err.command, 'SET');
|
||||
done();
|
||||
});
|
||||
});
|
||||
describe('and no callback is specified', function () {
|
||||
describe('with valid parameters', function () {
|
||||
it('sets the value correctly', function (done) {
|
||||
client.set(key, value)
|
||||
client.get(key, helper.isString(value, done))
|
||||
})
|
||||
|
||||
it('empty array as second parameter', function (done) {
|
||||
client.set('foo', [], function (err, res) {
|
||||
assert.strictEqual(err.message, "ERR wrong number of arguments for 'set' command");
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
it('sets the value correctly even if the callback is explicitly set to undefined', function (done) {
|
||||
client.set(key, value, undefined)
|
||||
client.get(key, helper.isString(value, done))
|
||||
})
|
||||
|
||||
describe('and no callback is specified', function () {
|
||||
describe('with valid parameters', function () {
|
||||
it('sets the value correctly', function (done) {
|
||||
client.set(key, value);
|
||||
client.get(key, helper.isString(value, done));
|
||||
});
|
||||
it('sets the value correctly with the array syntax', function (done) {
|
||||
client.set([key, value])
|
||||
client.get(key, helper.isString(value, done))
|
||||
})
|
||||
})
|
||||
|
||||
it('sets the value correctly even if the callback is explicitly set to undefined', function (done) {
|
||||
client.set(key, value, undefined);
|
||||
client.get(key, helper.isString(value, done));
|
||||
});
|
||||
describe('with undefined \'key\' and missing \'value\' parameter', function () {
|
||||
it('emits an error without callback', function (done) {
|
||||
client.on('error', function (err) {
|
||||
assert.strictEqual(err.message, 'ERR wrong number of arguments for \'set\' command')
|
||||
assert.strictEqual(err.command, 'SET')
|
||||
done()
|
||||
})
|
||||
client.set(undefined)
|
||||
})
|
||||
})
|
||||
|
||||
it('sets the value correctly with the array syntax', function (done) {
|
||||
client.set([key, value]);
|
||||
client.get(key, helper.isString(value, done));
|
||||
});
|
||||
});
|
||||
// TODO: This test has to be refactored from v.3.0 on to expect an error instead
|
||||
it('converts null to \'null\'', function (done) {
|
||||
client.set('foo', null)
|
||||
client.get('foo', helper.isString('null', done))
|
||||
})
|
||||
|
||||
describe("with undefined 'key' and missing 'value' parameter", function () {
|
||||
it('emits an error without callback', function (done) {
|
||||
client.on('error', function (err) {
|
||||
assert.equal(err.message, "ERR wrong number of arguments for 'set' command");
|
||||
assert.equal(err.command, 'SET');
|
||||
done();
|
||||
});
|
||||
client.set(undefined);
|
||||
});
|
||||
});
|
||||
it('emit an error with only the key set', function (done) {
|
||||
client.on('error', function (err) {
|
||||
assert.strictEqual(err.message, 'ERR wrong number of arguments for \'set\' command')
|
||||
done()
|
||||
})
|
||||
|
||||
// TODO: This test has to be refactored from v.3.0 on to expect an error instead
|
||||
it("converts null to 'null'", function (done) {
|
||||
client.set('foo', null);
|
||||
client.get('foo', helper.isString('null', done));
|
||||
});
|
||||
client.set('foo')
|
||||
})
|
||||
|
||||
it('emit an error with only the key set', function (done) {
|
||||
client.on('error', function (err) {
|
||||
assert.equal(err.message, "ERR wrong number of arguments for 'set' command");
|
||||
done();
|
||||
});
|
||||
|
||||
client.set('foo');
|
||||
});
|
||||
|
||||
it('emit an error without any parameters', function (done) {
|
||||
client.once('error', function (err) {
|
||||
assert.equal(err.message, "ERR wrong number of arguments for 'set' command");
|
||||
assert.equal(err.command, 'SET');
|
||||
done();
|
||||
});
|
||||
client.set();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
it('emit an error without any parameters', function (done) {
|
||||
client.once('error', function (err) {
|
||||
assert.strictEqual(err.message, 'ERR wrong number of arguments for \'set\' command')
|
||||
assert.strictEqual(err.command, 'SET')
|
||||
done()
|
||||
})
|
||||
client.set()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,37 +1,36 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var assert = require('assert');
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var assert = require('assert')
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
|
||||
describe("The 'setex' method", function () {
|
||||
describe('The \'setex\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
var client
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var client;
|
||||
it('sets a key with an expiry', function (done) {
|
||||
client.setex(['setex key', '100', 'setex val'], helper.isString('OK'))
|
||||
var buffering = client.exists(['setex key'], helper.isNumber(1))
|
||||
assert(typeof buffering === 'boolean')
|
||||
client.ttl(['setex key'], function (err, ttl) {
|
||||
assert.strictEqual(err, null)
|
||||
assert(ttl > 0)
|
||||
return done()
|
||||
})
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done);
|
||||
});
|
||||
});
|
||||
|
||||
it('sets a key with an expiry', function (done) {
|
||||
client.setex(['setex key', '100', 'setex val'], helper.isString('OK'));
|
||||
var buffering = client.exists(['setex key'], helper.isNumber(1));
|
||||
assert(typeof buffering === 'boolean');
|
||||
client.ttl(['setex key'], function (err, ttl) {
|
||||
assert(ttl > 0);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,37 +1,35 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
|
||||
describe("The 'setnx' method", function () {
|
||||
describe('The \'setnx\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
var client
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var client;
|
||||
it('sets key if it does not have a value', function (done) {
|
||||
client.setnx('foo', 'banana', helper.isNumber(1))
|
||||
client.get('foo', helper.isString('banana', done))
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done);
|
||||
});
|
||||
});
|
||||
it('does not set key if it already has a value', function (done) {
|
||||
client.set('foo', 'bar', helper.isString('OK'))
|
||||
client.setnx('foo', 'banana', helper.isNumber(0))
|
||||
client.get('foo', helper.isString('bar', done))
|
||||
})
|
||||
|
||||
it('sets key if it does not have a value', function (done) {
|
||||
client.setnx('foo', 'banana', helper.isNumber(1));
|
||||
client.get('foo', helper.isString('banana', done));
|
||||
});
|
||||
|
||||
it('does not set key if it already has a value', function (done) {
|
||||
client.set('foo', 'bar', helper.isString('OK'));
|
||||
client.setnx('foo', 'banana', helper.isNumber(0));
|
||||
client.get('foo', helper.isString('bar', done));
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,63 +1,61 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var assert = require('assert');
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var assert = require('assert')
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
|
||||
describe("The 'sinter' method", function () {
|
||||
describe('The \'sinter\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
var client
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var client;
|
||||
it('handles two sets being intersected', function (done) {
|
||||
client.sadd('sa', 'a', helper.isNumber(1))
|
||||
client.sadd('sa', 'b', helper.isNumber(1))
|
||||
client.sadd('sa', 'c', helper.isNumber(1))
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done);
|
||||
});
|
||||
});
|
||||
client.sadd('sb', 'b', helper.isNumber(1))
|
||||
client.sadd('sb', 'c', helper.isNumber(1))
|
||||
client.sadd('sb', 'd', helper.isNumber(1))
|
||||
|
||||
it('handles two sets being intersected', function (done) {
|
||||
client.sadd('sa', 'a', helper.isNumber(1));
|
||||
client.sadd('sa', 'b', helper.isNumber(1));
|
||||
client.sadd('sa', 'c', helper.isNumber(1));
|
||||
client.sinter('sa', 'sb', function (err, intersection) {
|
||||
assert.strictEqual(intersection.length, 2)
|
||||
assert.deepEqual(intersection.sort(), [ 'b', 'c' ])
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
|
||||
client.sadd('sb', 'b', helper.isNumber(1));
|
||||
client.sadd('sb', 'c', helper.isNumber(1));
|
||||
client.sadd('sb', 'd', helper.isNumber(1));
|
||||
it('handles three sets being intersected', function (done) {
|
||||
client.sadd('sa', 'a', helper.isNumber(1))
|
||||
client.sadd('sa', 'b', helper.isNumber(1))
|
||||
client.sadd('sa', 'c', helper.isNumber(1))
|
||||
|
||||
client.sinter('sa', 'sb', function (err, intersection) {
|
||||
assert.equal(intersection.length, 2);
|
||||
assert.deepEqual(intersection.sort(), [ 'b', 'c' ]);
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
client.sadd('sb', 'b', helper.isNumber(1))
|
||||
client.sadd('sb', 'c', helper.isNumber(1))
|
||||
client.sadd('sb', 'd', helper.isNumber(1))
|
||||
|
||||
it('handles three sets being intersected', function (done) {
|
||||
client.sadd('sa', 'a', helper.isNumber(1));
|
||||
client.sadd('sa', 'b', helper.isNumber(1));
|
||||
client.sadd('sa', 'c', helper.isNumber(1));
|
||||
client.sadd('sc', 'c', helper.isNumber(1))
|
||||
client.sadd('sc', 'd', helper.isNumber(1))
|
||||
client.sadd('sc', 'e', helper.isNumber(1))
|
||||
|
||||
client.sadd('sb', 'b', helper.isNumber(1));
|
||||
client.sadd('sb', 'c', helper.isNumber(1));
|
||||
client.sadd('sb', 'd', helper.isNumber(1));
|
||||
client.sinter('sa', 'sb', 'sc', function (err, intersection) {
|
||||
assert.strictEqual(intersection.length, 1)
|
||||
assert.strictEqual(intersection[0], 'c')
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
|
||||
client.sadd('sc', 'c', helper.isNumber(1));
|
||||
client.sadd('sc', 'd', helper.isNumber(1));
|
||||
client.sadd('sc', 'e', helper.isNumber(1));
|
||||
|
||||
client.sinter('sa', 'sb', 'sc', function (err, intersection) {
|
||||
assert.equal(intersection.length, 1);
|
||||
assert.equal(intersection[0], 'c');
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,48 +1,46 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var assert = require('assert');
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var assert = require('assert')
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
|
||||
describe("The 'sinterstore' method", function () {
|
||||
describe('The \'sinterstore\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
var client
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var client;
|
||||
it('calculates set intersection and stores it in a key', function (done) {
|
||||
client.sadd('sa', 'a', helper.isNumber(1))
|
||||
client.sadd('sa', 'b', helper.isNumber(1))
|
||||
client.sadd('sa', 'c', helper.isNumber(1))
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done);
|
||||
});
|
||||
});
|
||||
client.sadd('sb', 'b', helper.isNumber(1))
|
||||
client.sadd('sb', 'c', helper.isNumber(1))
|
||||
client.sadd('sb', 'd', helper.isNumber(1))
|
||||
|
||||
it('calculates set intersection and stores it in a key', function (done) {
|
||||
client.sadd('sa', 'a', helper.isNumber(1));
|
||||
client.sadd('sa', 'b', helper.isNumber(1));
|
||||
client.sadd('sa', 'c', helper.isNumber(1));
|
||||
client.sadd('sc', 'c', helper.isNumber(1))
|
||||
client.sadd('sc', 'd', helper.isNumber(1))
|
||||
client.sadd('sc', 'e', helper.isNumber(1))
|
||||
|
||||
client.sadd('sb', 'b', helper.isNumber(1));
|
||||
client.sadd('sb', 'c', helper.isNumber(1));
|
||||
client.sadd('sb', 'd', helper.isNumber(1));
|
||||
client.sinterstore('foo', 'sa', 'sb', 'sc', helper.isNumber(1))
|
||||
|
||||
client.sadd('sc', 'c', helper.isNumber(1));
|
||||
client.sadd('sc', 'd', helper.isNumber(1));
|
||||
client.sadd('sc', 'e', helper.isNumber(1));
|
||||
client.smembers('foo', function (err, members) {
|
||||
assert.deepEqual(members, [ 'c' ])
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
|
||||
client.sinterstore('foo', 'sa', 'sb', 'sc', helper.isNumber(1));
|
||||
|
||||
client.smembers('foo', function (err, members) {
|
||||
assert.deepEqual(members, [ 'c' ]);
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,35 +1,33 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
|
||||
describe("The 'sismember' method", function () {
|
||||
describe('The \'sismember\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
var client
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var client;
|
||||
it('returns 0 if the value is not in the set', function (done) {
|
||||
client.sismember('foo', 'banana', helper.isNumber(0, done))
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done);
|
||||
});
|
||||
});
|
||||
it('returns 1 if the value is in the set', function (done) {
|
||||
client.sadd('foo', 'banana', helper.isNumber(1))
|
||||
client.sismember('foo', 'banana', helper.isNumber(1, done))
|
||||
})
|
||||
|
||||
it('returns 0 if the value is not in the set', function (done) {
|
||||
client.sismember('foo', 'banana', helper.isNumber(0, done));
|
||||
});
|
||||
|
||||
it('returns 1 if the value is in the set', function (done) {
|
||||
client.sadd('foo', 'banana', helper.isNumber(1));
|
||||
client.sismember('foo', 'banana', helper.isNumber(1, done));
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,41 +1,39 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var assert = require('assert');
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var assert = require('assert')
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
|
||||
describe("The 'slowlog' method", function () {
|
||||
describe('The \'slowlog\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
var client
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var client;
|
||||
it('logs operations in slowlog', function (done) {
|
||||
client.config('set', 'slowlog-log-slower-than', 0, helper.isString('OK'))
|
||||
client.slowlog('reset', helper.isString('OK'))
|
||||
client.set('foo', 'bar', helper.isString('OK'))
|
||||
client.get('foo', helper.isString('bar'))
|
||||
client.slowlog('get', function (err, res) {
|
||||
assert.strictEqual(res.length, 3)
|
||||
assert.strictEqual(res[0][3].length, 2)
|
||||
assert.deepEqual(res[1][3], ['set', 'foo', 'bar'])
|
||||
assert.deepEqual(res[2][3], ['slowlog', 'reset'])
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done);
|
||||
});
|
||||
});
|
||||
|
||||
it('logs operations in slowlog', function (done) {
|
||||
client.config('set', 'slowlog-log-slower-than', 0, helper.isString('OK'));
|
||||
client.slowlog('reset', helper.isString('OK'));
|
||||
client.set('foo', 'bar', helper.isString('OK'));
|
||||
client.get('foo', helper.isString('bar'));
|
||||
client.slowlog('get', function (err, res) {
|
||||
assert.equal(res.length, 3);
|
||||
assert.equal(res[0][3].length, 2);
|
||||
assert.deepEqual(res[1][3], ['set', 'foo', 'bar']);
|
||||
assert.deepEqual(res[2][3], ['slowlog', 'reset']);
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,38 +1,36 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var assert = require('assert');
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var assert = require('assert')
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
|
||||
describe("The 'smembers' method", function () {
|
||||
describe('The \'smembers\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
var client
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var client;
|
||||
it('returns all values in a set', function (done) {
|
||||
client.sadd('foo', 'x', helper.isNumber(1))
|
||||
client.sadd('foo', 'y', helper.isNumber(1))
|
||||
client.smembers('foo', function (err, values) {
|
||||
assert.strictEqual(values.length, 2)
|
||||
var members = values.sort()
|
||||
assert.deepEqual(members, [ 'x', 'y' ])
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done);
|
||||
});
|
||||
});
|
||||
|
||||
it('returns all values in a set', function (done) {
|
||||
client.sadd('foo', 'x', helper.isNumber(1));
|
||||
client.sadd('foo', 'y', helper.isNumber(1));
|
||||
client.smembers('foo', function (err, values) {
|
||||
assert.equal(values.length, 2);
|
||||
var members = values.sort();
|
||||
assert.deepEqual(members, [ 'x', 'y' ]);
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,40 +1,38 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
|
||||
describe("The 'smove' method", function () {
|
||||
describe('The \'smove\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
var client
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var client;
|
||||
it('moves a value to a set that does not yet exist', function (done) {
|
||||
client.sadd('foo', 'x', helper.isNumber(1))
|
||||
client.smove('foo', 'bar', 'x', helper.isNumber(1))
|
||||
client.sismember('foo', 'x', helper.isNumber(0))
|
||||
client.sismember('bar', 'x', helper.isNumber(1, done))
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done);
|
||||
});
|
||||
});
|
||||
it('does not move a value if it does not exist in the first set', function (done) {
|
||||
client.sadd('foo', 'x', helper.isNumber(1))
|
||||
client.smove('foo', 'bar', 'y', helper.isNumber(0))
|
||||
client.sismember('foo', 'y', helper.isNumber(0))
|
||||
client.sismember('bar', 'y', helper.isNumber(0, done))
|
||||
})
|
||||
|
||||
it('moves a value to a set that does not yet exist', function (done) {
|
||||
client.sadd('foo', 'x', helper.isNumber(1));
|
||||
client.smove('foo', 'bar', 'x', helper.isNumber(1));
|
||||
client.sismember('foo', 'x', helper.isNumber(0));
|
||||
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) {
|
||||
client.sadd('foo', 'x', helper.isNumber(1));
|
||||
client.smove('foo', 'bar', 'y', helper.isNumber(0));
|
||||
client.sismember('foo', 'y', helper.isNumber(0));
|
||||
client.sismember('bar', 'y', helper.isNumber(0, done));
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,130 +1,127 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var assert = require('assert');
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var assert = require('assert')
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
|
||||
function setupData (client, done) {
|
||||
client.rpush('y', 'd');
|
||||
client.rpush('y', 'b');
|
||||
client.rpush('y', 'a');
|
||||
client.rpush('y', 'c');
|
||||
client.rpush('y', 'd')
|
||||
client.rpush('y', 'b')
|
||||
client.rpush('y', 'a')
|
||||
client.rpush('y', 'c')
|
||||
|
||||
client.rpush('x', '3');
|
||||
client.rpush('x', '9');
|
||||
client.rpush('x', '2');
|
||||
client.rpush('x', '4');
|
||||
client.rpush('x', '3')
|
||||
client.rpush('x', '9')
|
||||
client.rpush('x', '2')
|
||||
client.rpush('x', '4')
|
||||
|
||||
client.set('w3', '4');
|
||||
client.set('w9', '5');
|
||||
client.set('w2', '12');
|
||||
client.set('w4', '6');
|
||||
client.set('w3', '4')
|
||||
client.set('w9', '5')
|
||||
client.set('w2', '12')
|
||||
client.set('w4', '6')
|
||||
|
||||
client.set('o2', 'buz');
|
||||
client.set('o3', 'foo');
|
||||
client.set('o4', 'baz');
|
||||
client.set('o9', 'bar');
|
||||
client.set('o2', 'buz')
|
||||
client.set('o3', 'foo')
|
||||
client.set('o4', 'baz')
|
||||
client.set('o9', 'bar')
|
||||
|
||||
client.set('p2', 'qux');
|
||||
client.set('p3', 'bux');
|
||||
client.set('p4', 'lux');
|
||||
client.set('p9', 'tux', done);
|
||||
client.set('p2', 'qux')
|
||||
client.set('p3', 'bux')
|
||||
client.set('p4', 'lux')
|
||||
client.set('p9', 'tux', done)
|
||||
}
|
||||
|
||||
describe("The 'sort' method", function () {
|
||||
describe('The \'sort\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
var client
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('error', done)
|
||||
client.once('connect', function () {
|
||||
client.flushdb()
|
||||
setupData(client, done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var client;
|
||||
describe('alphabetical', function () {
|
||||
it('sorts in ascending alphabetical order', function (done) {
|
||||
client.sort('y', 'asc', 'alpha', function (err, sorted) {
|
||||
assert.deepEqual(sorted, ['a', 'b', 'c', 'd'])
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('error', done);
|
||||
client.once('connect', function () {
|
||||
client.flushdb();
|
||||
setupData(client, done);
|
||||
});
|
||||
});
|
||||
it('sorts in descending alphabetical order', function (done) {
|
||||
client.sort('y', 'desc', 'alpha', function (err, sorted) {
|
||||
assert.deepEqual(sorted, ['d', 'c', 'b', 'a'])
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('alphabetical', function () {
|
||||
it('sorts in ascending alphabetical order', function (done) {
|
||||
client.sort('y', 'asc', 'alpha', function (err, sorted) {
|
||||
assert.deepEqual(sorted, ['a', 'b', 'c', 'd']);
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
describe('numeric', function () {
|
||||
it('sorts in ascending numeric order', function (done) {
|
||||
client.sort('x', 'asc', function (err, sorted) {
|
||||
assert.deepEqual(sorted, [2, 3, 4, 9])
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
|
||||
it('sorts in descending alphabetical order', function (done) {
|
||||
client.sort('y', 'desc', 'alpha', function (err, sorted) {
|
||||
assert.deepEqual(sorted, ['d', 'c', 'b', 'a']);
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
it('sorts in descending numeric order', function (done) {
|
||||
client.sort('x', 'desc', function (err, sorted) {
|
||||
assert.deepEqual(sorted, [9, 4, 3, 2])
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('numeric', function () {
|
||||
it('sorts in ascending numeric order', function (done) {
|
||||
client.sort('x', 'asc', function (err, sorted) {
|
||||
assert.deepEqual(sorted, [2, 3, 4, 9]);
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
describe('pattern', function () {
|
||||
it('handles sorting with a pattern', function (done) {
|
||||
client.sort('x', 'by', 'w*', 'asc', function (err, sorted) {
|
||||
assert.deepEqual(sorted, [3, 9, 4, 2])
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
|
||||
it('sorts in descending numeric order', function (done) {
|
||||
client.sort('x', 'desc', function (err, sorted) {
|
||||
assert.deepEqual(sorted, [9, 4, 3, 2]);
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
it('handles sorting with a \'by\' pattern and 1 \'get\' pattern', function (done) {
|
||||
client.sort('x', 'by', 'w*', 'asc', 'get', 'o*', function (err, sorted) {
|
||||
assert.deepEqual(sorted, ['foo', 'bar', 'baz', 'buz'])
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
|
||||
describe('pattern', function () {
|
||||
it('handles sorting with a pattern', function (done) {
|
||||
client.sort('x', 'by', 'w*', 'asc', function (err, sorted) {
|
||||
assert.deepEqual(sorted, [3, 9, 4, 2]);
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
it('handles sorting with a \'by\' pattern and 2 \'get\' patterns', function (done) {
|
||||
client.sort('x', 'by', 'w*', 'asc', 'get', 'o*', 'get', 'p*', function (err, sorted) {
|
||||
assert.deepEqual(sorted, ['foo', 'bux', 'bar', 'tux', 'baz', 'lux', 'buz', 'qux'])
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
|
||||
it("handles sorting with a 'by' pattern and 1 'get' pattern", function (done) {
|
||||
client.sort('x', 'by', 'w*', 'asc', 'get', 'o*', function (err, sorted) {
|
||||
assert.deepEqual(sorted, ['foo', 'bar', 'baz', 'buz']);
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
it('handles sorting with a \'by\' pattern and 2 \'get\' patterns with the array syntax', function (done) {
|
||||
client.sort(['x', 'by', 'w*', 'asc', 'get', 'o*', 'get', 'p*'], function (err, sorted) {
|
||||
assert.deepEqual(sorted, ['foo', 'bux', 'bar', 'tux', 'baz', 'lux', 'buz', 'qux'])
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
|
||||
it("handles sorting with a 'by' pattern and 2 'get' patterns", function (done) {
|
||||
client.sort('x', 'by', 'w*', 'asc', 'get', 'o*', 'get', 'p*', function (err, sorted) {
|
||||
assert.deepEqual(sorted, ['foo', 'bux', 'bar', 'tux', 'baz', 'lux', 'buz', 'qux']);
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
it('sorting with a \'by\' pattern and 2 \'get\' patterns and stores results', function (done) {
|
||||
client.sort('x', 'by', 'w*', 'asc', 'get', 'o*', 'get', 'p*', 'store', 'bacon', function (err) {
|
||||
if (err) return done(err)
|
||||
})
|
||||
|
||||
it("handles sorting with a 'by' pattern and 2 'get' patterns with the array syntax", function (done) {
|
||||
client.sort(['x', 'by', 'w*', 'asc', 'get', 'o*', 'get', 'p*'], function (err, sorted) {
|
||||
assert.deepEqual(sorted, ['foo', 'bux', 'bar', 'tux', 'baz', 'lux', 'buz', 'qux']);
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
client.lrange('bacon', 0, -1, function (err, values) {
|
||||
assert.deepEqual(values, ['foo', 'bux', 'bar', 'tux', 'baz', 'lux', 'buz', 'qux'])
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it("sorting with a 'by' pattern and 2 'get' patterns and stores results", function (done) {
|
||||
client.sort('x', 'by', 'w*', 'asc', 'get', 'o*', 'get', 'p*', 'store', 'bacon', function (err) {
|
||||
if (err) return done(err);
|
||||
});
|
||||
|
||||
client.lrange('bacon', 0, -1, function (err, values) {
|
||||
assert.deepEqual(values, ['foo', 'bux', 'bar', 'tux', 'baz', 'lux', 'buz', 'qux']);
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,38 +1,36 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var assert = require('assert');
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var assert = require('assert')
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
|
||||
describe("The 'spop' method", function () {
|
||||
describe('The \'spop\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
var client
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var client;
|
||||
it('returns a random element from the set', function (done) {
|
||||
client.sadd('zzz', 'member0', helper.isNumber(1))
|
||||
client.scard('zzz', helper.isNumber(1))
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done);
|
||||
});
|
||||
});
|
||||
client.spop('zzz', function (err, value) {
|
||||
if (err) return done(err)
|
||||
assert.strictEqual(value, 'member0')
|
||||
client.scard('zzz', helper.isNumber(0, done))
|
||||
})
|
||||
})
|
||||
|
||||
it('returns a random element from the set', function (done) {
|
||||
client.sadd('zzz', 'member0', helper.isNumber(1));
|
||||
client.scard('zzz', helper.isNumber(1));
|
||||
|
||||
client.spop('zzz', function (err, value) {
|
||||
if (err) return done(err);
|
||||
assert.equal(value, 'member0');
|
||||
client.scard('zzz', helper.isNumber(0, done));
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,69 +1,67 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var assert = require('assert');
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var assert = require('assert')
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
|
||||
describe("The 'srem' method", function () {
|
||||
describe('The \'srem\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
var client
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var client;
|
||||
it('removes a value', function (done) {
|
||||
client.sadd('set0', 'member0', helper.isNumber(1))
|
||||
client.srem('set0', 'member0', helper.isNumber(1))
|
||||
client.scard('set0', helper.isNumber(0, done))
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done);
|
||||
});
|
||||
});
|
||||
it('handles attempting to remove a missing value', function (done) {
|
||||
client.srem('set0', 'member0', helper.isNumber(0, done))
|
||||
})
|
||||
|
||||
it('removes a value', function (done) {
|
||||
client.sadd('set0', 'member0', helper.isNumber(1));
|
||||
client.srem('set0', 'member0', helper.isNumber(1));
|
||||
client.scard('set0', helper.isNumber(0, done));
|
||||
});
|
||||
it('allows multiple values to be removed', function (done) {
|
||||
client.sadd('set0', ['member0', 'member1', 'member2'], helper.isNumber(3))
|
||||
client.srem('set0', ['member1', 'member2'], helper.isNumber(2))
|
||||
client.smembers('set0', function (err, res) {
|
||||
assert.strictEqual(res.length, 1)
|
||||
assert.ok(~res.indexOf('member0'))
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
|
||||
it('handles attempting to remove a missing value', function (done) {
|
||||
client.srem('set0', 'member0', helper.isNumber(0, done));
|
||||
});
|
||||
it('allows multiple values to be removed with sendCommand', function (done) {
|
||||
client.sendCommand('sadd', ['set0', 'member0', 'member1', 'member2'], helper.isNumber(3))
|
||||
client.sendCommand('srem', ['set0', 'member1', 'member2'], helper.isNumber(2))
|
||||
client.smembers('set0', function (err, res) {
|
||||
assert.strictEqual(res.length, 1)
|
||||
assert.ok(~res.indexOf('member0'))
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
|
||||
it('allows multiple values to be removed', function (done) {
|
||||
client.sadd('set0', ['member0', 'member1', 'member2'], helper.isNumber(3));
|
||||
client.srem('set0', ['member1', 'member2'], helper.isNumber(2));
|
||||
client.smembers('set0', function (err, res) {
|
||||
assert.strictEqual(res.length, 1);
|
||||
assert.ok(~res.indexOf('member0'));
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
it('handles a value missing from the set of values being removed', function (done) {
|
||||
client.sadd(['set0', 'member0', 'member1', 'member2'], helper.isNumber(3))
|
||||
client.srem(['set0', 'member3', 'member4'], helper.isNumber(0))
|
||||
client.smembers('set0', function (err, res) {
|
||||
assert.strictEqual(res.length, 3)
|
||||
assert.ok(~res.indexOf('member0'))
|
||||
assert.ok(~res.indexOf('member1'))
|
||||
assert.ok(~res.indexOf('member2'))
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
|
||||
it('allows multiple values to be removed with sendCommand', function (done) {
|
||||
client.sendCommand('sadd', ['set0', 'member0', 'member1', 'member2'], helper.isNumber(3));
|
||||
client.sendCommand('srem', ['set0', 'member1', 'member2'], helper.isNumber(2));
|
||||
client.smembers('set0', function (err, res) {
|
||||
assert.strictEqual(res.length, 1);
|
||||
assert.ok(~res.indexOf('member0'));
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
|
||||
it('handles a value missing from the set of values being removed', function (done) {
|
||||
client.sadd(['set0', 'member0', 'member1', 'member2'], helper.isNumber(3));
|
||||
client.srem(['set0', 'member3', 'member4'], helper.isNumber(0));
|
||||
client.smembers('set0', function (err, res) {
|
||||
assert.strictEqual(res.length, 3);
|
||||
assert.ok(~res.indexOf('member0'));
|
||||
assert.ok(~res.indexOf('member1'));
|
||||
assert.ok(~res.indexOf('member2'));
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,46 +1,44 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var assert = require('assert');
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var assert = require('assert')
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
|
||||
describe("The 'sunion' method", function () {
|
||||
describe('The \'sunion\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
var client
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var client;
|
||||
it('returns the union of a group of sets', function (done) {
|
||||
client.sadd('sa', 'a', helper.isNumber(1))
|
||||
client.sadd('sa', 'b', helper.isNumber(1))
|
||||
client.sadd('sa', 'c', helper.isNumber(1))
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done);
|
||||
});
|
||||
});
|
||||
client.sadd('sb', 'b', helper.isNumber(1))
|
||||
client.sadd('sb', 'c', helper.isNumber(1))
|
||||
client.sadd('sb', 'd', helper.isNumber(1))
|
||||
|
||||
it('returns the union of a group of sets', function (done) {
|
||||
client.sadd('sa', 'a', helper.isNumber(1));
|
||||
client.sadd('sa', 'b', helper.isNumber(1));
|
||||
client.sadd('sa', 'c', helper.isNumber(1));
|
||||
client.sadd('sc', 'c', helper.isNumber(1))
|
||||
client.sadd('sc', 'd', helper.isNumber(1))
|
||||
client.sadd('sc', 'e', helper.isNumber(1))
|
||||
|
||||
client.sadd('sb', 'b', helper.isNumber(1));
|
||||
client.sadd('sb', 'c', helper.isNumber(1));
|
||||
client.sadd('sb', 'd', helper.isNumber(1));
|
||||
client.sunion('sa', 'sb', 'sc', function (err, union) {
|
||||
assert.deepEqual(union.sort(), ['a', 'b', 'c', 'd', 'e'])
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
|
||||
client.sadd('sc', 'c', helper.isNumber(1));
|
||||
client.sadd('sc', 'd', helper.isNumber(1));
|
||||
client.sadd('sc', 'e', helper.isNumber(1));
|
||||
|
||||
client.sunion('sa', 'sb', 'sc', function (err, union) {
|
||||
assert.deepEqual(union.sort(), ['a', 'b', 'c', 'd', 'e']);
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,49 +1,47 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var assert = require('assert');
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var assert = require('assert')
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
|
||||
describe("The 'sunionstore' method", function () {
|
||||
describe('The \'sunionstore\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
var client
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var client;
|
||||
it('stores the result of a union', function (done) {
|
||||
client.sadd('sa', 'a', helper.isNumber(1))
|
||||
client.sadd('sa', 'b', helper.isNumber(1))
|
||||
client.sadd('sa', 'c', helper.isNumber(1))
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done);
|
||||
});
|
||||
});
|
||||
client.sadd('sb', 'b', helper.isNumber(1))
|
||||
client.sadd('sb', 'c', helper.isNumber(1))
|
||||
client.sadd('sb', 'd', helper.isNumber(1))
|
||||
|
||||
it('stores the result of a union', function (done) {
|
||||
client.sadd('sa', 'a', helper.isNumber(1));
|
||||
client.sadd('sa', 'b', helper.isNumber(1));
|
||||
client.sadd('sa', 'c', helper.isNumber(1));
|
||||
client.sadd('sc', 'c', helper.isNumber(1))
|
||||
client.sadd('sc', 'd', helper.isNumber(1))
|
||||
client.sadd('sc', 'e', helper.isNumber(1))
|
||||
|
||||
client.sadd('sb', 'b', helper.isNumber(1));
|
||||
client.sadd('sb', 'c', helper.isNumber(1));
|
||||
client.sadd('sb', 'd', helper.isNumber(1));
|
||||
client.sunionstore('foo', 'sa', 'sb', 'sc', helper.isNumber(5))
|
||||
|
||||
client.sadd('sc', 'c', helper.isNumber(1));
|
||||
client.sadd('sc', 'd', helper.isNumber(1));
|
||||
client.sadd('sc', 'e', helper.isNumber(1));
|
||||
client.smembers('foo', function (err, members) {
|
||||
assert.strictEqual(members.length, 5)
|
||||
assert.deepEqual(members.sort(), ['a', 'b', 'c', 'd', 'e'])
|
||||
return done(err)
|
||||
})
|
||||
})
|
||||
|
||||
client.sunionstore('foo', 'sa', 'sb', 'sc', helper.isNumber(5));
|
||||
|
||||
client.smembers('foo', function (err, members) {
|
||||
assert.equal(members.length, 5);
|
||||
assert.deepEqual(members.sort(), ['a', 'b', 'c', 'd', 'e']);
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,37 +1,35 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var assert = require('assert');
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var assert = require('assert')
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
|
||||
describe("The 'ttl' method", function () {
|
||||
describe('The \'ttl\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
var client
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var client;
|
||||
it('returns the current ttl on a key', function (done) {
|
||||
client.set(['ttl key', 'ttl val'], helper.isString('OK'))
|
||||
client.expire(['ttl key', '100'], helper.isNumber(1))
|
||||
client.ttl(['ttl key'], function (err, ttl) {
|
||||
assert(ttl >= 99)
|
||||
assert(ttl <= 100)
|
||||
done(err)
|
||||
})
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done);
|
||||
});
|
||||
});
|
||||
|
||||
it('returns the current ttl on a key', function (done) {
|
||||
client.set(['ttl key', 'ttl val'], helper.isString('OK'));
|
||||
client.expire(['ttl key', '100'], helper.isNumber(1));
|
||||
client.ttl(['ttl key'], function (err, ttl) {
|
||||
assert(ttl >= 99);
|
||||
assert(ttl <= 100);
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,56 +1,53 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
|
||||
describe("The 'type' method", function () {
|
||||
describe('The \'type\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
var client
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var client;
|
||||
it('reports string type', function (done) {
|
||||
client.set(['string key', 'should be a string'], helper.isString('OK'))
|
||||
client.type(['string key'], helper.isString('string', done))
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done);
|
||||
});
|
||||
});
|
||||
it('reports list type', function (done) {
|
||||
client.rpush(['list key', 'should be a list'], helper.isNumber(1))
|
||||
client.type(['list key'], helper.isString('list', done))
|
||||
})
|
||||
|
||||
it('reports string type', function (done) {
|
||||
client.set(['string key', 'should be a string'], helper.isString('OK'));
|
||||
client.type(['string key'], helper.isString('string', done));
|
||||
});
|
||||
it('reports set type', function (done) {
|
||||
client.sadd(['set key', 'should be a set'], helper.isNumber(1))
|
||||
client.type(['set key'], helper.isString('set', done))
|
||||
})
|
||||
|
||||
it('reports list type', function (done) {
|
||||
client.rpush(['list key', 'should be a list'], helper.isNumber(1));
|
||||
client.type(['list key'], helper.isString('list', done));
|
||||
});
|
||||
it('reports zset type', function (done) {
|
||||
client.zadd('zset key', ['10.0', 'should be a zset'], helper.isNumber(1))
|
||||
client.type(['zset key'], helper.isString('zset', done))
|
||||
})
|
||||
|
||||
it('reports set type', function (done) {
|
||||
client.sadd(['set key', 'should be a set'], helper.isNumber(1));
|
||||
client.type(['set key'], helper.isString('set', done));
|
||||
});
|
||||
it('reports hash type', function (done) {
|
||||
client.hset('hash key', 'hashtest', 'should be a hash', helper.isNumber(1))
|
||||
client.type(['hash key'], helper.isString('hash', done))
|
||||
})
|
||||
|
||||
it('reports zset type', function (done) {
|
||||
client.zadd('zset key', ['10.0', 'should be a zset'], helper.isNumber(1));
|
||||
client.type(['zset key'], helper.isString('zset', done));
|
||||
});
|
||||
it('reports none for null key', function (done) {
|
||||
client.type('not here yet', helper.isString('none', done))
|
||||
})
|
||||
|
||||
it('reports hash type', function (done) {
|
||||
client.hset('hash key', 'hashtest', 'should be a hash', helper.isNumber(1));
|
||||
client.type(['hash key'], helper.isString('hash', done));
|
||||
});
|
||||
|
||||
it('reports none for null key', function (done) {
|
||||
client.type('not here yet', helper.isString('none', done));
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,54 +1,50 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var assert = require('assert');
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var redis = config.redis;
|
||||
var assert = require('assert')
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
|
||||
describe("The 'watch' method", function () {
|
||||
describe('The \'watch\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
var watched = 'foobar'
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
var client
|
||||
|
||||
var watched = 'foobar';
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var client;
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done);
|
||||
});
|
||||
});
|
||||
it('does not execute transaction if watched key was modified prior to execution', function (done) {
|
||||
client.watch(watched)
|
||||
client.incr(watched)
|
||||
var multi = client.multi()
|
||||
multi.incr(watched)
|
||||
multi.exec(helper.isNull(done))
|
||||
})
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
it('successfully modifies other keys independently of transaction', function (done) {
|
||||
client.set('unwatched', 200)
|
||||
|
||||
it('does not execute transaction if watched key was modified prior to execution', function (done) {
|
||||
client.watch(watched);
|
||||
client.incr(watched);
|
||||
var multi = client.multi();
|
||||
multi.incr(watched);
|
||||
multi.exec(helper.isNull(done));
|
||||
});
|
||||
client.set(watched, 0)
|
||||
client.watch(watched)
|
||||
client.incr(watched)
|
||||
|
||||
it('successfully modifies other keys independently of transaction', function (done) {
|
||||
client.set('unwatched', 200);
|
||||
client.multi().incr(watched).exec(function (err, replies) {
|
||||
assert.strictEqual(err, null)
|
||||
assert.strictEqual(replies, null, 'Aborted transaction multi-bulk reply should be null.')
|
||||
|
||||
client.set(watched, 0);
|
||||
client.watch(watched);
|
||||
client.incr(watched);
|
||||
|
||||
client.multi().incr(watched).exec(function (err, replies) {
|
||||
assert.strictEqual(replies, null, 'Aborted transaction multi-bulk reply should be null.');
|
||||
|
||||
client.get('unwatched', function (err, reply) {
|
||||
assert.equal(reply, 200, 'Expected 200, got ' + reply);
|
||||
return done(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
client.get('unwatched', helper.isString('200', done))
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,48 +1,46 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var assert = require('assert');
|
||||
var redis = config.redis;
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var assert = require('assert')
|
||||
var redis = config.redis
|
||||
|
||||
describe("The 'zadd' method", function () {
|
||||
describe('The \'zadd\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
var client
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var client;
|
||||
it('reports an error', function (done) {
|
||||
if (helper.redisProcess().spawnFailed()) this.skip()
|
||||
client.zadd('infinity', [+'5t', 'should not be possible'], helper.isError(done))
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done);
|
||||
});
|
||||
});
|
||||
it('return inf / -inf', function (done) {
|
||||
if (helper.redisProcess().spawnFailed()) this.skip()
|
||||
helper.serverVersionAtLeast.call(this, client, [3, 0, 2])
|
||||
client.zadd('infinity', [+Infinity, 'should be inf'], helper.isNumber(1))
|
||||
client.zadd('infinity', ['inf', 'should be also be inf'], helper.isNumber(1))
|
||||
client.zadd('infinity', -Infinity, 'should be negative inf', helper.isNumber(1))
|
||||
client.zadd('infinity', [99999999999999999999999, 'should not be inf'], helper.isNumber(1))
|
||||
client.zrange('infinity', 0, -1, 'WITHSCORES', function (err, res) {
|
||||
assert.strictEqual(err, null)
|
||||
assert.strictEqual(res[5], 'inf')
|
||||
assert.strictEqual(res[1], '-inf')
|
||||
assert.strictEqual(res[3], '9.9999999999999992e+22')
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('reports an error', function (done) {
|
||||
if (helper.redisProcess().spawnFailed()) this.skip();
|
||||
client.zadd('infinity', [+'5t', 'should not be possible'], helper.isError(done));
|
||||
});
|
||||
|
||||
it('return inf / -inf', function (done) {
|
||||
if (helper.redisProcess().spawnFailed()) this.skip();
|
||||
helper.serverVersionAtLeast.call(this, client, [3, 0, 2]);
|
||||
client.zadd('infinity', [+Infinity, 'should be inf'], helper.isNumber(1));
|
||||
client.zadd('infinity', ['inf', 'should be also be inf'], helper.isNumber(1));
|
||||
client.zadd('infinity', -Infinity, 'should be negative inf', helper.isNumber(1));
|
||||
client.zadd('infinity', [99999999999999999999999, 'should not be inf'], helper.isNumber(1));
|
||||
client.zrange('infinity', 0, -1, 'WITHSCORES', function (err, res) {
|
||||
assert.equal(res[5], 'inf');
|
||||
assert.equal(res[1], '-inf');
|
||||
assert.equal(res[3], '9.9999999999999992e+22');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,50 +1,47 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var assert = require('assert');
|
||||
var redis = config.redis;
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var assert = require('assert')
|
||||
var redis = config.redis
|
||||
|
||||
describe("The 'zscan' method", function () {
|
||||
describe('The \'zscan\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
var client
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var client;
|
||||
it('return values', function (done) {
|
||||
if (helper.redisProcess().spawnFailed()) this.skip()
|
||||
helper.serverVersionAtLeast.call(this, client, [2, 8, 0])
|
||||
var hash = {}
|
||||
var set = []
|
||||
var zset = ['zset:1']
|
||||
for (var i = 0; i < 500; i++) {
|
||||
hash['key_' + i] = 'value_' + i
|
||||
set.push('member_' + i)
|
||||
zset.push(i, 'zMember_' + i)
|
||||
}
|
||||
client.hmset('hash:1', hash)
|
||||
client.sadd('set:1', set)
|
||||
client.zadd(zset)
|
||||
client.zscan('zset:1', 0, 'MATCH', '*', 'COUNT', 500, function (err, res) {
|
||||
assert(!err)
|
||||
assert.strictEqual(res.length, 2)
|
||||
assert.strictEqual(res[1].length, 1000)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done);
|
||||
});
|
||||
});
|
||||
|
||||
it('return values', function (done) {
|
||||
if (helper.redisProcess().spawnFailed()) this.skip();
|
||||
helper.serverVersionAtLeast.call(this, client, [2, 8, 0]);
|
||||
var hash = {};
|
||||
var set = [];
|
||||
var zset = ['zset:1'];
|
||||
for (var i = 0; i < 500; i++) {
|
||||
hash['key_' + i] = 'value_' + i;
|
||||
set.push('member_' + i);
|
||||
zset.push(i, 'zMember_' + i);
|
||||
}
|
||||
client.hmset('hash:1', hash);
|
||||
client.sadd('set:1', set);
|
||||
client.zadd(zset);
|
||||
client.zscan('zset:1', 0, 'MATCH', '*', 'COUNT', 500, function (err, res) {
|
||||
assert(!err);
|
||||
assert.strictEqual(res.length, 2);
|
||||
assert.strictEqual(res[1].length, 1000);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@@ -1,35 +1,29 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
var config = require('../lib/config');
|
||||
var helper = require('../helper');
|
||||
var assert = require('assert');
|
||||
var redis = config.redis;
|
||||
var config = require('../lib/config')
|
||||
var helper = require('../helper')
|
||||
var redis = config.redis
|
||||
|
||||
describe("The 'zscore' method", function () {
|
||||
describe('The \'zscore\' method', function () {
|
||||
helper.allTests(function (ip, args) {
|
||||
describe('using ' + ip, function () {
|
||||
var client
|
||||
|
||||
helper.allTests(function (ip, args) {
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('using ' + ip, function () {
|
||||
var client;
|
||||
it('should return the score of member in the sorted set at key', function (done) {
|
||||
client.zadd('myzset', 1, 'one')
|
||||
client.zscore('myzset', 'one', helper.isString('1', done))
|
||||
})
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
client.flushdb(done);
|
||||
});
|
||||
});
|
||||
|
||||
it('should return the score of member in the sorted set at key', function (done) {
|
||||
client.zadd('myzset', 1, 'one');
|
||||
client.zscore('myzset', 'one', function (err, res) {
|
||||
assert.equal(res, 1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
client.end(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
afterEach(function () {
|
||||
client.end(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user