1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-07 13:22:56 +03:00

chore - remove standard and use individual config

Standard is not as up to date and still uses a old eslint version.
Instead, use the airbnb default with a couple of modifications.

All required changes are included.
This commit is contained in:
Ruben Bridgewater
2017-11-28 21:38:21 -02:00
parent 0206ecbf51
commit 2b4ab10305
97 changed files with 888 additions and 673 deletions

View File

@@ -3,7 +3,8 @@
const assert = require('assert')
const config = require('./lib/config')
const helper = require('./helper')
const redis = config.redis
const { redis } = config
// TODO: Fix redis process spawn on windows
if (process.platform !== 'win32') {
@@ -215,7 +216,8 @@ if (process.platform !== 'win32') {
})
})
client.once('ready', () => {
// Coherent behavior with all other offline commands fires commands before emitting but does not wait till they return
// Coherent behavior with all other offline commands fires commands
// before emitting but does not wait till they return
assert.strictEqual(client._pubSubMode, 2)
client.ping().then(() => { // Make sure all commands were properly processed already
client._stream.destroy()
@@ -224,11 +226,15 @@ if (process.platform !== 'win32') {
})
it('individual commands work properly with batch', (done) => {
// quit => might return an error instead of "OK" in the exec callback... (if not connected)
// auth => might return an error instead of "OK" in the exec callback... (if no password is required / still loading on Redis <= 2.4)
// This could be fixed by checking the return value of the callback in the exec callback and
// returning the manipulated [error, result] from the callback.
// There should be a better solution though
// quit => might return an error instead of "OK" in the exec callback...
// (if not connected)
//
// auth => might return an error instead of "OK" in the exec callback...
// (if no password is required / still loading on Redis <= 2.4)
//
// This could be fixed by checking the return value of the callback in
// the exec callback and returning the manipulated [error, result] from
// the callback. There should be a better solution though
const args = config.configureClient('localhost', {
noReadyCheck: true
@@ -240,25 +246,26 @@ if (process.platform !== 'win32') {
end() // Should be called for each command after monitor
})
client.batch()
.auth(auth)
.select(5)
.monitor()
.set('foo', 'bar')
.info('stats')
.get('foo')
.subscribe(['foo', 'bar', 'foo'])
.unsubscribe('foo')
.subscribe('/foo')
.psubscribe('*')
.quit()
.exec().then((res) => {
res[4] = res[4].substr(0, 9)
assert.deepStrictEqual(
res,
['OK', 'OK', 'OK', 'OK', '# Stats\r\n', 'bar', [2, ['foo', 'bar', 'foo']], [1, ['foo']], [2, ['/foo']], [3, ['*']], 'OK']
)
end()
})
.auth(auth)
.select(5)
.monitor()
.set('foo', 'bar')
.info('stats')
.get('foo')
.subscribe(['foo', 'bar', 'foo'])
.unsubscribe('foo')
.subscribe('/foo')
.psubscribe('*')
.quit()
.exec()
.then((res) => {
res[4] = res[4].substr(0, 9)
assert.deepStrictEqual(
res,
['OK', 'OK', 'OK', 'OK', '# Stats\r\n', 'bar', [2, ['foo', 'bar', 'foo']], [1, ['foo']], [2, ['/foo']], [3, ['*']], 'OK']
)
end()
})
})
})
})

View File

@@ -3,7 +3,8 @@
const assert = require('assert')
const config = require('./lib/config')
const helper = require('./helper')
const redis = config.redis
const { redis } = config
describe('The \'batch\' method', () => {
helper.allTests((ip, args) => {
@@ -101,7 +102,7 @@ describe('The \'batch\' method', () => {
['incr', 'batchfoo'],
['incr', 'batchbar']
]).exec().then(helper.fail).catch((err) => {
const replies = err.replies
const { replies } = err
assert.strictEqual(2, replies[0].length)
assert.strictEqual(null, replies[0][0])
assert.strictEqual(null, replies[0][1])
@@ -150,8 +151,8 @@ describe('The \'batch\' method', () => {
[['hmset', 'batchhmset2', 'batchbar2', 'batchfoo3', 'batchbar3', 'test']],
['hmset', ['batchhmset', 'batchbar', 'batchfoo']],
['hmset', arr3],
['hmset', now, {123456789: 'abcdefghij', 'some manner of key': 'a type of value', 'otherTypes': 555}],
['hmset', 'key2', {'0123456789': 'abcdefghij', 'some manner of key': 'a type of value', 'otherTypes': 999}],
['hmset', now, { 123456789: 'abcdefghij', 'some manner of key': 'a type of value', otherTypes: 555 }],
['hmset', 'key2', { '0123456789': 'abcdefghij', 'some manner of key': 'a type of value', otherTypes: 999 }],
['hmset', new Set(['batchhmset', ['batchbar', 'batchbaz']])],
['hmset', ['batchhmset'], new Map([['batchbar', 'batchbaz']])]
])
@@ -159,7 +160,8 @@ describe('The \'batch\' method', () => {
.hmget('key2', arr2)
.hmget(['batchhmset2', ['some manner of key', 'batchbar3']])
.mget('batchfoo2', ['batchfoo3', 'batchfoo'])
.exec().then((replies) => {
.exec()
.then((replies) => {
assert.strictEqual(arr.length, 3)
assert.strictEqual(arr2.length, 2)
assert.strictEqual(arr3.length, 3)
@@ -194,7 +196,8 @@ describe('The \'batch\' method', () => {
.incr('some')
.incr('keys')
.mget('some', 'keys')
.exec().then(helper.isDeepEqual(['OK', 11, 21, ['11', '21']]))
.exec()
.then(helper.isDeepEqual(['OK', 11, 21, ['11', '21']]))
})
it('allows multiple commands to work the same as normal to be performed using a chaining API', () => {
@@ -203,7 +206,8 @@ describe('The \'batch\' method', () => {
.incr('some')
.incr(['keys'])
.mget('some', 'keys')
.exec().then(helper.isDeepEqual(['OK', 11, 21, ['11', '21']]))
.exec()
.then(helper.isDeepEqual(['OK', 11, 21, ['11', '21']]))
})
it('allows an array to be provided indicating multiple operations to perform', () => {

View File

@@ -3,7 +3,8 @@
const assert = require('assert')
const config = require('../lib/config')
const helper = require('../helper')
const redis = config.redis
const { redis } = config
const intercept = require('intercept-stdout')
describe('The \'blpop\' method', () => {

View File

@@ -1,10 +1,11 @@
'use strict'
const Buffer = require('buffer').Buffer
const { Buffer } = require('buffer')
const assert = require('assert')
const config = require('../lib/config')
const helper = require('../helper')
const redis = config.redis
const { redis } = config
describe('The \'client\' method', () => {
helper.allTests((ip, args) => {
@@ -144,8 +145,9 @@ describe('The \'client\' method', () => {
})
it('sets the name', () => {
// 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
// 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
return Promise.all([
client.client('setname', 'RUTH'),
client2.client('setname', ['RENEE']).then(helper.isString('OK')),

View File

@@ -3,13 +3,15 @@
const assert = require('assert')
const config = require('../lib/config')
const helper = require('../helper')
const redis = config.redis
const { redis } = config
const uuid = require('uuid')
describe('The \'dbsize\' method', () => {
helper.allTests((ip, args) => {
describe(`using ${ip}`, () => {
let key, value
let key
let value
beforeEach(() => {
key = uuid.v4()

View File

@@ -2,7 +2,8 @@
const config = require('../lib/config')
const helper = require('../helper')
const redis = config.redis
const { redis } = config
describe('The \'del\' method', () => {
helper.allTests((ip, args) => {

View File

@@ -4,7 +4,8 @@ const assert = require('assert')
const config = require('../lib/config')
const crypto = require('crypto')
const helper = require('../helper')
const redis = config.redis
const { redis } = config
describe('The \'eval\' method', () => {
helper.allTests((ip, args) => {
@@ -121,7 +122,8 @@ describe('The \'eval\' method', () => {
.rpush('mylist', 'a')
.rpush('mylist', 'b')
.rpush('mylist', 'c')
.exec().then((replies) => {
.exec()
.then((replies) => {
return client.eval('local foo = redis.call(\'lrange\',\'mylist\',0,-1); return {type(foo),foo[1],foo[2],foo[3],# foo}', 0).then((res) => {
assert.strictEqual(5, res.length)
assert.strictEqual('table', res[0])

View File

@@ -2,7 +2,8 @@
const config = require('../lib/config')
const helper = require('../helper')
const redis = config.redis
const { redis } = config
describe('The \'exists\' method', () => {
helper.allTests((ip, args) => {

View File

@@ -2,7 +2,8 @@
const config = require('../lib/config')
const helper = require('../helper')
const redis = config.redis
const { redis } = config
describe('The \'expire\' method', () => {
helper.allTests((ip, args) => {

View File

@@ -2,13 +2,15 @@
const config = require('../lib/config')
const helper = require('../helper')
const redis = config.redis
const { redis } = config
const uuid = require('uuid')
describe('The \'flushdb\' method', () => {
helper.allTests((ip, args) => {
describe(`using ${ip}`, () => {
let key, key2
let key
let key2
beforeEach(() => {
key = uuid.v4()

View File

@@ -2,7 +2,8 @@
const config = require('../lib/config')
const helper = require('../helper')
const redis = config.redis
const { redis } = config
describe('The \'geoadd\' method', () => {
helper.allTests((ip, args) => {

View File

@@ -2,13 +2,15 @@
const config = require('../lib/config')
const helper = require('../helper')
const redis = config.redis
const { redis } = config
const uuid = require('uuid')
describe('The \'get\' method', () => {
helper.allTests((ip, args) => {
describe(`using ${ip}`, () => {
let key, value
let key
let value
beforeEach(() => {
key = uuid.v4()

View File

@@ -2,13 +2,16 @@
const config = require('../lib/config')
const helper = require('../helper')
const redis = config.redis
const { redis } = config
const uuid = require('uuid')
describe('The \'getset\' method', () => {
helper.allTests((ip, args) => {
describe(`using ${ip}`, () => {
let key, value, value2
let key
let value
let value2
beforeEach(() => {
key = uuid.v4()

View File

@@ -1,10 +1,11 @@
'use strict'
const Buffer = require('buffer').Buffer
const { Buffer } = require('buffer')
const assert = require('assert')
const config = require('../lib/config')
const helper = require('../helper')
const redis = config.redis
const { redis } = config
describe('The \'hgetall\' method', () => {
helper.allTests((ip, args) => {

View File

@@ -2,7 +2,8 @@
const config = require('../lib/config')
const helper = require('../helper')
const redis = config.redis
const { redis } = config
describe('The \'hincrby\' method', () => {
helper.allTests((ip, args) => {

View File

@@ -1,9 +1,10 @@
'use strict'
const Buffer = require('buffer').Buffer
const { Buffer } = require('buffer')
const config = require('../lib/config')
const helper = require('../helper')
const redis = config.redis
const { redis } = config
describe('The \'hlen\' method', () => {
helper.allTests((ip, args) => {

View File

@@ -2,7 +2,8 @@
const config = require('../lib/config')
const helper = require('../helper')
const redis = config.redis
const { redis } = config
describe('The \'hmget\' method', () => {
helper.allTests((ip, args) => {
@@ -13,7 +14,7 @@ describe('The \'hmget\' method', () => {
beforeEach(() => {
client = redis.createClient.apply(null, args)
client.flushdb()
return client.hmset(hash, {'0123456789': 'abcdefghij', 'some manner of key': 'a type of value'})
return client.hmset(hash, { '0123456789': 'abcdefghij', 'some manner of key': 'a type of value' })
.then(helper.isString('OK'))
})

View File

@@ -2,7 +2,8 @@
const config = require('../lib/config')
const helper = require('../helper')
const redis = config.redis
const { redis } = config
describe('The \'hmset\' method', () => {
helper.allTests((ip, args) => {
@@ -20,25 +21,25 @@ describe('The \'hmset\' method', () => {
return client.hgetall(hash).then(helper.isDeepEqual({
'0123456789': 'abcdefghij',
'some manner of key': 'a type of value',
'otherTypes': '555'
otherTypes: '555'
}))
})
it('handles object-style syntax', () => {
client.hmset(hash, {'0123456789': 'abcdefghij', 'some manner of key': 'a type of value', 'otherTypes': 555}).then(helper.isString('OK'))
client.hmset(hash, { '0123456789': 'abcdefghij', 'some manner of key': 'a type of value', otherTypes: 555 }).then(helper.isString('OK'))
return client.hgetall(hash).then(helper.isDeepEqual({
'0123456789': 'abcdefghij',
'some manner of key': 'a type of value',
'otherTypes': '555'
otherTypes: '555'
}))
})
it('handles object-style syntax and the key being a number', () => {
client.hmset(231232, {'0123456789': 'abcdefghij', 'some manner of key': 'a type of value', 'otherTypes': 555})
client.hmset(231232, { '0123456789': 'abcdefghij', 'some manner of key': 'a type of value', otherTypes: 555 })
return client.hgetall(231232).then(helper.isDeepEqual({
'0123456789': 'abcdefghij',
'some manner of key': 'a type of value',
'otherTypes': '555'
otherTypes: '555'
}))
})

View File

@@ -1,10 +1,11 @@
'use strict'
const Buffer = require('buffer').Buffer
const { Buffer } = require('buffer')
const assert = require('assert')
const config = require('../lib/config')
const helper = require('../helper')
const redis = config.redis
const { redis } = config
describe('The \'hset\' method', () => {
helper.allTests((ip, args) => {
@@ -43,8 +44,9 @@ describe('The \'hset\' method', () => {
it('warns if someone passed a array either as field or as value', () => {
const hash = 'test hash'
const 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
// 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
const value = ['array contents']
return client.hmset(hash, field, value).then(assert, helper.isError())
})

View File

@@ -2,7 +2,8 @@
const config = require('../lib/config')
const helper = require('../helper')
const redis = config.redis
const { redis } = config
describe('The \'incr\' method', () => {
helper.allTests((ip, args) => {

View File

@@ -3,7 +3,8 @@
const assert = require('assert')
const config = require('../lib/config')
const helper = require('../helper')
const redis = config.redis
const { redis } = config
describe('The \'info\' method', () => {
helper.allTests((ip, args) => {

View File

@@ -4,7 +4,8 @@ const assert = require('assert')
const config = require('../lib/config')
const crypto = require('crypto')
const helper = require('../helper')
const redis = config.redis
const { redis } = config
describe('The \'keys\' method', () => {
helper.allTests((ip, args) => {
@@ -20,8 +21,8 @@ describe('The \'keys\' method', () => {
client.mset(['test keys 1', 'test val 1', 'test keys 2', 'test val 2']).then(helper.isString('OK'))
return client.keys('test keys*').then((results) => {
assert.strictEqual(2, results.length)
assert.ok(~results.indexOf('test keys 1'))
assert.ok(~results.indexOf('test keys 2'))
assert.notStrictEqual(results.indexOf('test keys 1'), -1)
assert.notStrictEqual(results.indexOf('test keys 2'), -1)
})
})
@@ -39,7 +40,7 @@ describe('The \'keys\' method', () => {
client.mset(keysValues.reduce((a, b) => a.concat(b))).then(helper.isString('OK'))
return client.keys('multibulk:*').then((results) => {
assert.deepStrictEqual(keysValues.map((val) => val[0]).sort(), results.sort())
assert.deepStrictEqual(keysValues.map(val => val[0]).sort(), results.sort())
})
})

View File

@@ -2,7 +2,8 @@
const config = require('../lib/config')
const helper = require('../helper')
const redis = config.redis
const { redis } = config
describe('The \'mget\' method', () => {
helper.allTests((ip, args) => {

View File

@@ -1,11 +1,12 @@
'use strict'
const Buffer = require('buffer').Buffer
const { Buffer } = require('buffer')
const assert = require('assert')
const config = require('../lib/config')
const helper = require('../helper')
const utils = require('../../lib/utils')
const redis = config.redis
const { redis } = config
describe('The \'monitor\' method', () => {
helper.allTests((parser, ip, args) => {
@@ -185,8 +186,9 @@ describe('The \'monitor\' method', () => {
assert.deepStrictEqual(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
// 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(() => {
assert(called)
pub.end(false)

View File

@@ -3,13 +3,17 @@
const assert = require('assert')
const config = require('../lib/config')
const helper = require('../helper')
const redis = config.redis
const { redis } = config
const uuid = require('uuid')
describe('The \'mset\' method', () => {
helper.allTests((ip, args) => {
describe(`using ${ip}`, () => {
let key, value, key2, value2
let key
let value
let key2
let value2
beforeEach(() => {
key = uuid.v4()

View File

@@ -2,7 +2,8 @@
const config = require('../lib/config')
const helper = require('../helper')
const redis = config.redis
const { redis } = config
describe('The \'msetnx\' method', () => {
helper.allTests((ip, args) => {

View File

@@ -3,7 +3,8 @@
const assert = require('assert')
const config = require('../lib/config')
const helper = require('../helper')
const redis = config.redis
const { redis } = config
describe('The \'randomkey\' method', () => {
helper.allTests((ip, args) => {

View File

@@ -2,7 +2,8 @@
const config = require('../lib/config')
const helper = require('../helper')
const redis = config.redis
const { redis } = config
describe('The \'rename\' method', () => {
helper.allTests((ip, args) => {

View File

@@ -2,7 +2,8 @@
const config = require('../lib/config')
const helper = require('../helper')
const redis = config.redis
const { redis } = config
describe('The \'renamenx\' method', () => {
helper.allTests((ip, args) => {

View File

@@ -2,7 +2,8 @@
const config = require('../lib/config')
const helper = require('../helper')
const redis = config.redis
const { redis } = config
describe('The \'rpush\' command', () => {
helper.allTests((ip, args) => {

View File

@@ -3,7 +3,8 @@
const assert = require('assert')
const config = require('../lib/config')
const helper = require('../helper')
const redis = config.redis
const { redis } = config
describe('The \'sadd\' method', () => {
helper.allTests((ip, args) => {
@@ -18,7 +19,7 @@ describe('The \'sadd\' method', () => {
it('allows a single value to be added to the set', () => {
client.sadd('set0', 'member0').then(helper.isNumber(1))
return client.smembers('set0').then((res) => {
assert.ok(~res.indexOf('member0'))
assert.notStrictEqual(res.indexOf('member0'), -1)
})
})
@@ -31,9 +32,9 @@ describe('The \'sadd\' method', () => {
client.sadd('set0', ['member0', 'member1', 'member2']).then(helper.isNumber(3))
return client.smembers('set0').then((res) => {
assert.strictEqual(res.length, 3)
assert.ok(~res.indexOf('member0'))
assert.ok(~res.indexOf('member1'))
assert.ok(~res.indexOf('member2'))
assert.notStrictEqual(res.indexOf('member0'), -1)
assert.notStrictEqual(res.indexOf('member1'), -1)
assert.notStrictEqual(res.indexOf('member2'), -1)
})
})
@@ -41,9 +42,9 @@ describe('The \'sadd\' method', () => {
client.sadd(['set0', 'member0', 'member1', 'member2']).then(helper.isNumber(3))
return client.smembers('set0').then((res) => {
assert.strictEqual(res.length, 3)
assert.ok(~res.indexOf('member0'))
assert.ok(~res.indexOf('member1'))
assert.ok(~res.indexOf('member2'))
assert.notStrictEqual(res.indexOf('member0'), -1)
assert.notStrictEqual(res.indexOf('member1'), -1)
assert.notStrictEqual(res.indexOf('member2'), -1)
})
})

View File

@@ -2,7 +2,8 @@
const config = require('../lib/config')
const helper = require('../helper')
const redis = config.redis
const { redis } = config
describe('The \'scard\' method', () => {
helper.allTests((ip, args) => {

View File

@@ -3,7 +3,8 @@
const config = require('../lib/config')
const crypto = require('crypto')
const helper = require('../helper')
const redis = config.redis
const { redis } = config
describe('The \'script\' method', () => {
helper.allTests((ip, args) => {

View File

@@ -3,7 +3,8 @@
const assert = require('assert')
const config = require('../lib/config')
const helper = require('../helper')
const redis = config.redis
const { redis } = config
describe('The \'sdiff\' method', () => {
helper.allTests((ip, args) => {

View File

@@ -3,7 +3,8 @@
const assert = require('assert')
const config = require('../lib/config')
const helper = require('../helper')
const redis = config.redis
const { redis } = config
describe('The \'sdiffstore\' method', () => {
helper.allTests((ip, args) => {
@@ -28,7 +29,7 @@ describe('The \'sdiffstore\' method', () => {
return client.smembers('quux').then((values) => {
const members = values.sort()
assert.deepStrictEqual(members, [ 'b', 'x' ])
assert.deepStrictEqual(members, ['b', 'x'])
})
})

View File

@@ -3,7 +3,8 @@
const assert = require('assert')
const config = require('../lib/config')
const helper = require('../helper')
const redis = config.redis
const { redis } = config
describe('The \'select\' method', () => {
helper.allTests((ip, args) => {

View File

@@ -3,13 +3,15 @@
const assert = require('assert')
const config = require('../lib/config')
const helper = require('../helper')
const redis = config.redis
const { redis } = config
const uuid = require('uuid')
describe('The \'set\' method', () => {
helper.allTests((ip, args) => {
describe(`using ${ip}`, () => {
let key, value
let key
let value
beforeEach(() => {
key = uuid.v4()

View File

@@ -3,7 +3,8 @@
const assert = require('assert')
const config = require('../lib/config')
const helper = require('../helper')
const redis = config.redis
const { redis } = config
describe('The \'setex\' method', () => {
helper.allTests((ip, args) => {

View File

@@ -2,7 +2,8 @@
const config = require('../lib/config')
const helper = require('../helper')
const redis = config.redis
const { redis } = config
describe('The \'setnx\' method', () => {
helper.allTests((ip, args) => {

View File

@@ -3,7 +3,8 @@
const assert = require('assert')
const config = require('../lib/config')
const helper = require('../helper')
const redis = config.redis
const { redis } = config
describe('The \'sinter\' method', () => {
helper.allTests((ip, args) => {
@@ -26,7 +27,7 @@ describe('The \'sinter\' method', () => {
return client.sinter('sa', 'sb').then((intersection) => {
assert.strictEqual(intersection.length, 2)
assert.deepStrictEqual(intersection.sort(), [ 'b', 'c' ])
assert.deepStrictEqual(intersection.sort(), ['b', 'c'])
})
})

View File

@@ -2,7 +2,8 @@
const config = require('../lib/config')
const helper = require('../helper')
const redis = config.redis
const { redis } = config
describe('The \'sinterstore\' method', () => {
helper.allTests((ip, args) => {

View File

@@ -2,7 +2,8 @@
const config = require('../lib/config')
const helper = require('../helper')
const redis = config.redis
const { redis } = config
describe('The \'sismember\' method', () => {
helper.allTests((ip, args) => {

View File

@@ -3,7 +3,8 @@
const assert = require('assert')
const config = require('../lib/config')
const helper = require('../helper')
const redis = config.redis
const { redis } = config
describe('The \'slowlog\' method', () => {
helper.allTests((ip, args) => {

View File

@@ -3,7 +3,8 @@
const assert = require('assert')
const config = require('../lib/config')
const helper = require('../helper')
const redis = config.redis
const { redis } = config
describe('The \'smembers\' method', () => {
helper.allTests((ip, args) => {
@@ -21,7 +22,7 @@ describe('The \'smembers\' method', () => {
return client.smembers('foo').then((values) => {
assert.strictEqual(values.length, 2)
const members = values.sort()
assert.deepStrictEqual(members, [ 'x', 'y' ])
assert.deepStrictEqual(members, ['x', 'y'])
})
})

View File

@@ -2,7 +2,8 @@
const config = require('../lib/config')
const helper = require('../helper')
const redis = config.redis
const { redis } = config
describe('The \'smove\' method', () => {
helper.allTests((ip, args) => {

View File

@@ -2,9 +2,10 @@
const config = require('../lib/config')
const helper = require('../helper')
const redis = config.redis
function setupData (client) {
const { redis } = config
function setupData(client) {
client.rpush('y', 'd')
client.rpush('y', 'b')
client.rpush('y', 'a')

View File

@@ -2,7 +2,8 @@
const config = require('../lib/config')
const helper = require('../helper')
const redis = config.redis
const { redis } = config
describe('The \'spop\' method', () => {
helper.allTests((ip, args) => {

View File

@@ -3,7 +3,8 @@
const assert = require('assert')
const config = require('../lib/config')
const helper = require('../helper')
const redis = config.redis
const { redis } = config
describe('The \'srem\' method', () => {
helper.allTests((ip, args) => {
@@ -30,7 +31,7 @@ describe('The \'srem\' method', () => {
client.srem('set0', ['member1', 'member2']).then(helper.isNumber(2))
return client.smembers('set0').then((res) => {
assert.strictEqual(res.length, 1)
assert.ok(~res.indexOf('member0'))
assert.notStrictEqual(res.indexOf('member0'), -1)
})
})
@@ -39,7 +40,7 @@ describe('The \'srem\' method', () => {
client.sendCommand('srem', ['set0', 'member1', 'member2']).then(helper.isNumber(2))
return client.smembers('set0').then((res) => {
assert.strictEqual(res.length, 1)
assert.ok(~res.indexOf('member0'))
assert.notStrictEqual(res.indexOf('member0'), -1)
})
})
@@ -48,9 +49,9 @@ describe('The \'srem\' method', () => {
client.srem(['set0', 'member3', 'member4']).then(helper.isNumber(0))
return client.smembers('set0').then((res) => {
assert.strictEqual(res.length, 3)
assert.ok(~res.indexOf('member0'))
assert.ok(~res.indexOf('member1'))
assert.ok(~res.indexOf('member2'))
assert.notStrictEqual(res.indexOf('member0'), -1)
assert.notStrictEqual(res.indexOf('member1'), -1)
assert.notStrictEqual(res.indexOf('member2'), -1)
})
})

View File

@@ -3,7 +3,8 @@
const assert = require('assert')
const config = require('../lib/config')
const helper = require('../helper')
const redis = config.redis
const { redis } = config
describe('The \'sunion\' method', () => {
helper.allTests((ip, args) => {

View File

@@ -3,7 +3,8 @@
const assert = require('assert')
const config = require('../lib/config')
const helper = require('../helper')
const redis = config.redis
const { redis } = config
describe('The \'sunionstore\' method', () => {
helper.allTests((ip, args) => {

View File

@@ -3,7 +3,8 @@
const assert = require('assert')
const config = require('../lib/config')
const helper = require('../helper')
const redis = config.redis
const { redis } = config
describe('The \'ttl\' method', () => {
helper.allTests((ip, args) => {

View File

@@ -2,7 +2,8 @@
const config = require('../lib/config')
const helper = require('../helper')
const redis = config.redis
const { redis } = config
describe('The \'type\' method', () => {
helper.allTests((ip, args) => {

View File

@@ -3,7 +3,8 @@
const assert = require('assert')
const config = require('../lib/config')
const helper = require('../helper')
const redis = config.redis
const { redis } = config
describe('The \'watch\' method', () => {
helper.allTests((ip, args) => {

View File

@@ -3,7 +3,8 @@
const config = require('../lib/config')
const helper = require('../helper')
const assert = require('assert')
const redis = config.redis
const { redis } = config
describe('The \'zadd\' method', () => {
helper.allTests((ip, args) => {

View File

@@ -3,7 +3,8 @@
const config = require('../lib/config')
const helper = require('../helper')
const assert = require('assert')
const redis = config.redis
const { redis } = config
describe('The \'zscan\' method', () => {
helper.allTests((ip, args) => {

View File

@@ -2,7 +2,8 @@
const config = require('../lib/config')
const helper = require('../helper')
const redis = config.redis
const { redis } = config
describe('The \'zscore\' method', () => {
helper.allTests((ip, args) => {

View File

@@ -4,11 +4,13 @@ const assert = require('assert')
const config = require('./lib/config')
const helper = require('./helper')
const RedisProcess = require('./lib/redis-process')
let rp
const path = require('path')
const redis = config.redis
// TODO: Fix redis process spawn on windows
const { redis } = config
// TODO: Fix redis process spawn on windows
if (process.platform !== 'win32') {
describe('master slave sync', () => {
let master = null
@@ -29,7 +31,7 @@ if (process.platform !== 'win32') {
let i = 0
while (i < 1000) {
i++
// Write some data in the redis instance, so there's something to sync
// Write some data in the redis instance, so there's something to sync
multi.set(`foo${i}`, `bar${new Array(500).join(Math.random())}`)
}
return multi.exec()
@@ -42,8 +44,9 @@ if (process.platform !== 'win32') {
let firstInfo
slave = redis.createClient({
port,
retryStrategy (options) {
// Try to reconnect in very small intervals to catch the master_link_status down before the sync completes
retryStrategy(options) {
// Try to reconnect in very small intervals to catch the
// master_link_status down before the sync completes
return 10
}
})

View File

@@ -4,9 +4,11 @@ const assert = require('assert')
const config = require('./lib/config')
const connect = require('../lib/connect')
const helper = require('./helper')
const Redis = config.redis
const { Redis } = config
const intercept = require('intercept-stdout')
const net = require('net')
let client
describe('connection tests', () => {
@@ -18,9 +20,10 @@ describe('connection tests', () => {
})
it('support for a private stream', () => {
// While using a private stream, reconnecting and other features are not going to work properly.
// Besides that some functions also have to be monkey patched to be safe from errors in this case.
// Therefore this is not officially supported!
// While using a private stream, reconnecting and other features are not
// going to work properly. Besides that some functions also have to be
// monkey patched to be safe from errors in this case. Therefore this is not
// officially supported!
const socket = new net.Socket()
client = new Redis({
prefix: 'test',
@@ -41,7 +44,7 @@ describe('connection tests', () => {
client = Redis.createClient({
connectTimeout: 5,
port: 9999,
retryStrategy (options) {
retryStrategy(options) {
client.quit().then((res) => {
assert.strictEqual(res, 'OK')
assert.strictEqual(called++, -1)
@@ -158,7 +161,7 @@ describe('connection tests', () => {
host: 'somewhere',
port: 6379,
family: ip,
retryStrategy () {}
retryStrategy() {}
}
client = Redis.createClient(options)
assert.strictEqual(client._connectionOptions.family, ip === 'IPv6' ? 6 : 4)
@@ -172,7 +175,7 @@ describe('connection tests', () => {
it('retryStrategy used to reconnect with individual error', (done) => {
client = Redis.createClient({
retryStrategy (options) {
retryStrategy(options) {
if (options.totalRetryTime > 150) {
client.set('foo', 'bar').then(assert, (err) => {
assert.strictEqual(err.message, 'Stream connection ended and command aborted.')
@@ -191,7 +194,7 @@ describe('connection tests', () => {
it('retryStrategy used to reconnect', (done) => {
client = Redis.createClient({
retryStrategy (options) {
retryStrategy(options) {
if (options.totalRetryTime > 150) {
client.set('foo', 'bar').catch((err) => {
assert.strictEqual(err.message, 'Stream connection ended and command aborted.')
@@ -214,7 +217,7 @@ describe('connection tests', () => {
})
Redis.debugMode = true
client = Redis.createClient({
retryStrategy (options) {
retryStrategy(options) {
client.set('foo', 'bar').catch((err) => {
assert.strictEqual(err.code, 'NR_CLOSED')
assert.strictEqual(err.message, 'Stream connection ended and command aborted.')
@@ -241,7 +244,7 @@ describe('connection tests', () => {
// Auto detect ipv4 and use non routeable ip to trigger the timeout
host: '10.255.255.1',
connectTimeout,
retryStrategy () {
retryStrategy() {
return 5000
}
})
@@ -510,7 +513,7 @@ describe('connection tests', () => {
// Cover info parts with no value
setImmediate(() => {
const command = client.commandQueue.peekAt(0)
const callback = command.callback
const { callback } = command
command.callback = (err, res) => {
res += 'added:\r\n'
callback(err, res)
@@ -528,7 +531,8 @@ describe('connection tests', () => {
client.info = function () {
return tmp().then((res) => {
if (!delayed) {
// Try reconnecting after one second even if redis tells us the time needed is above one second
// Try reconnecting after one second even if redis tells us the
// time needed is above one second
client.serverInfo.persistence.loading = 1
client.serverInfo.persistence.loading_eta_seconds = 2.5
delayed = true

View File

@@ -1,10 +1,11 @@
'use strict'
const Buffer = require('buffer').Buffer
const { Buffer } = require('buffer')
const assert = require('assert')
const config = require('./lib/config')
const helper = require('./helper')
const redis = config.redis
const { redis } = config
describe('detectBuffers', () => {
let client
@@ -61,7 +62,8 @@ describe('detectBuffers', () => {
.hget(Buffer.from('hash key 2'), 'key 1')
.hget('hash key 2', Buffer.from('key 2'))
.hget('hash key 2', 'key 2')
.exec().then((reply) => {
.exec()
.then((reply) => {
assert.strictEqual(true, Array.isArray(reply))
assert.strictEqual(4, reply.length)
assert.strictEqual('val 1', reply[0])
@@ -81,7 +83,8 @@ describe('detectBuffers', () => {
.hget(Buffer.from('hash key 2'), 'key 1')
.hget('hash key 2', Buffer.from('key 2'))
.hget('hash key 2', 'key 2')
.exec().then((reply) => {
.exec()
.then((reply) => {
assert.strictEqual(true, Array.isArray(reply))
assert.strictEqual(4, reply.length)
assert.strictEqual('val 1', reply[0])

View File

@@ -3,8 +3,9 @@
const assert = require('assert')
const config = require('./lib/config')
const helper = require('./helper')
const fork = require('child_process').fork
const redis = config.redis
const { fork } = require('child_process')
const { redis } = config
describe('stack traces', () => {
it('should return good traces with NODE_ENV=development set', (done) => {

View File

@@ -5,6 +5,7 @@ const path = require('path')
const config = require('./lib/config')
const RedisProcess = require('./lib/redis-process')
const StunnelProcess = require('./lib/stunnel-process')
let rp
let stunnelProcess
@@ -16,7 +17,7 @@ process.on('unhandledRejection', (err, promise) => {
})
})
function startRedis (conf, done, port) {
function startRedis(conf, done, port) {
RedisProcess.start((err, _rp) => {
rp = _rp
return done(err)
@@ -37,7 +38,7 @@ if (!process.env.REDIS_TESTS_STARTED) {
})
}
function arrayHelper (results) {
function arrayHelper(results) {
if (results instanceof Array) {
assert.strictEqual(results.length, 1, 'The array length may only be one element')
return results[0]
@@ -45,7 +46,7 @@ function arrayHelper (results) {
return results
}
function toString (res) {
function toString(res) {
// If options are passed to return either strings or buffers...
if (Buffer.isBuffer(res)) {
return res.toString()
@@ -55,40 +56,40 @@ function toString (res) {
}
// Stringify all values as well
if (typeof res === 'object' && res !== null) {
Object.keys(res).map((key) => (res[key] = toString(res[key])))
Object.keys(res).forEach((key) => { res[key] = toString(res[key]) })
}
return res
}
module.exports = {
redisProcess () {
redisProcess() {
return rp
},
stopRedis (done) {
stopRedis(done) {
rp.stop(done)
},
startRedis,
stopStunnel (done) {
stopStunnel(done) {
if (stunnelProcess) {
StunnelProcess.stop(stunnelProcess, done)
} else {
done()
}
},
startStunnel (done) {
startStunnel(done) {
StunnelProcess.start((err, _stunnelProcess) => {
stunnelProcess = _stunnelProcess
return done(err)
}, path.resolve(__dirname, './conf'))
},
isNumber (expected) {
isNumber(expected) {
return function (results) {
results = arrayHelper(results)
assert.strictEqual(results, expected, `${expected} !== ${results}`)
assert.strictEqual(typeof results, 'number', `expected a number, got ${typeof results}`)
}
},
isString (str) {
isString(str) {
str = `${str}` // Make sure it's a string
return function (results) {
results = arrayHelper(results)
@@ -96,50 +97,51 @@ module.exports = {
assert.strictEqual(results, str, `${str} does not match ${results}`)
}
},
isNull () {
isNull() {
return function (results) {
results = arrayHelper(results)
assert.strictEqual(results, null, `${results} is not null`)
}
},
isUndefined () {
isUndefined() {
return function (results) {
results = arrayHelper(results)
assert.strictEqual(results, undefined, `${results} is not undefined`)
}
},
isError (regex) {
isError(regex) {
return function (err, res) {
assert.strictEqual(res, undefined, 'There should be an error, no result!')
assert(err instanceof Error, 'err is not instance of \'Error\', but an error is expected here.')
if (regex) assert(regex.test(err.message))
}
},
isDeepEqual (args) {
isDeepEqual(args) {
return function (res) {
res = toString(res)
assert.deepStrictEqual(res, args)
}
},
match (pattern) {
match(pattern) {
return function (results) {
results = arrayHelper(results)
assert(pattern.test(results), `expected string '${results}' to match ${pattern.toString()}`)
}
},
fail (err) {
fail(err) {
err = err instanceof Error
? err
: new Error('This should not be reachable')
throw err
},
serverVersionAtLeast (connection, desiredVersion) {
// Wait until a connection has established (otherwise a timeout is going to be triggered at some point)
serverVersionAtLeast(connection, desiredVersion) {
// Wait until a connection has established (otherwise a timeout is going to
// be triggered at some point)
if (Object.keys(connection.serverInfo).length === 0) {
throw new Error('Version check not possible as the client is not yet ready or did not expose the version')
}
// Return true if the server version >= desiredVersion
const version = connection.serverInfo.server.version
const { version } = connection.serverInfo.server
for (let i = 0; i < 3; i++) {
if (version[i] > desiredVersion[i]) {
return true
@@ -151,7 +153,7 @@ module.exports = {
}
return true
},
allTests (opts, cb) {
allTests(opts, cb) {
if (!cb) {
cb = opts
opts = {}
@@ -167,11 +169,9 @@ module.exports = {
}]
options.forEach((options) => {
let strOptions = ''
let key
for (key in options) {
if (options.hasOwnProperty(key)) {
strOptions += `${key}: ${options[key]}; `
}
const keys = Object.keys(options)
for (let i = 0; i < keys.length; i++) {
strOptions += `${keys[i]}: ${options[keys[i]]}; `
}
describe(`using options: ${strOptions}`, () => {
protocols.forEach((ip, i) => {
@@ -183,12 +183,12 @@ module.exports = {
})
})
},
removeMochaListener () {
removeMochaListener() {
const mochaListener = process.listeners('uncaughtException').pop()
process.removeListener('uncaughtException', mochaListener)
return mochaListener
},
callFuncAfter (func, max) {
callFuncAfter(func, max) {
let i = 0
return function () {
i++
@@ -199,7 +199,7 @@ module.exports = {
return false
}
},
killConnection (client) {
killConnection(client) {
// Change the connection option to a non existing one and destroy the stream
client._connectionOptions = {
port: 65535,

View File

@@ -11,7 +11,7 @@ const config = {
IPv4: '127.0.0.1',
IPv6: '::1'
},
configureClient (ip, opts) {
configureClient(ip, opts) {
const args = []
// Do not manipulate the opts => copy them each time
opts = opts ? JSON.parse(JSON.stringify(opts)) : {}

View File

@@ -1,8 +1,10 @@
// Spawned by the goodStacks.spec.js tests
'use strict'
const assert = require('assert')
const redis = require('../../index')
const client = redis.createClient()
// Both error cases would normally return bad stack traces

View File

@@ -9,7 +9,7 @@ const tcpPortUsed = require('tcp-port-used')
// wait for redis to be listening in
// all three modes (ipv4, ipv6, socket).
function waitForRedis (available, cb, port) {
function waitForRedis(available, cb, port) {
if (process.platform === 'win32') return cb()
const time = Date.now()
@@ -49,7 +49,7 @@ function waitForRedis (available, cb, port) {
}
module.exports = {
start (done, conf, port) {
start(done, conf, port) {
let spawnFailed = false
// spawn redis with our testing configuration.
const confFile = conf || path.resolve(__dirname, '../conf/redis.conf')
@@ -67,10 +67,10 @@ module.exports = {
// return an object that can be used in
// an after() block to shutdown redis.
return done(null, {
spawnFailed () {
spawnFailed() {
return spawnFailed
},
stop (done) {
stop(done) {
if (spawnFailed) return done()
rp.once('exit', (code) => {
let error = null

View File

@@ -1,22 +1,22 @@
'use strict'
// Helper to start and stop the stunnel process.
const spawn = require('child_process').spawn
const { spawn } = require('child_process')
const EventEmitter = require('events')
const fs = require('fs')
const path = require('path')
const util = require('util')
function once (cb) {
function once(cb) {
let called = false
return function () {
return function (...args) {
if (called) return
called = true
cb.apply(this, arguments)
cb.apply(this, args)
}
}
function StunnelProcess (confDir) {
function StunnelProcess(confDir) {
EventEmitter.call(this)
// Set up an stunnel to redis; edit the conf file to include required absolute paths
@@ -24,7 +24,8 @@ function StunnelProcess (confDir) {
const confText = fs.readFileSync(`${confFile}.template`).toString().replace(/__dirname/g, confDir)
fs.writeFileSync(confFile, confText)
const stunnel = this.stunnel = spawn('stunnel', [confFile])
this.stunnel = spawn('stunnel', [confFile])
const { stunnel } = this
// Handle child process events, and failure to set up tunnel
this.timer = setTimeout(() => {
@@ -67,13 +68,13 @@ StunnelProcess.prototype.stop = function (done) {
}
module.exports = {
start (done, confDir) {
done = once(done)
start(doneOrig, confDir) {
const done = once(doneOrig)
const stunnel = new StunnelProcess(confDir)
stunnel.once('error', done.bind(done))
stunnel.once('started', done.bind(done, null, stunnel))
},
stop (stunnel, done) {
stop(stunnel, done) {
stunnel.removeAllListeners()
stunnel.stop()
stunnel.once('error', done.bind(done))

View File

@@ -1,14 +1,16 @@
// spawned by the unref tests in nodeRedis.spec.js.
// when configured, unref causes the client to exit
// as soon as there are no outstanding commands.
'use strict'
const redis = require('../../index')
const HOST = process.argv[2] || '127.0.0.1'
const PORT = process.argv[3]
const args = PORT ? [PORT, HOST] : [HOST]
const c = redis.createClient.apply(redis, args)
const c = redis.createClient(...args)
c.info((err, reply) => {
if (err) process.exit(-1)
if (!reply.length) process.exit(-1)

View File

@@ -1,12 +1,14 @@
'use strict'
const Buffer = require('buffer').Buffer
const { Buffer } = require('buffer')
const assert = require('assert')
const config = require('./lib/config')
const helper = require('./helper')
const utils = require('../lib/utils')
const redis = config.redis
const { redis } = config
const zlib = require('zlib')
let client
describe('The \'multi\' method', () => {
@@ -23,32 +25,32 @@ describe('The \'multi\' method', () => {
// Some random object created from http://beta.json-generator.com/
const testObj = {
'Id': '5642c4c33d4667c4a1fefd99',
'index': 0,
'guid': '5baf1f1c-7621-41e7-ae7a-f8c6f3199b0f',
'isActive': true,
'balance': '$1,028.63',
'picture': 'http://placehold.it/32x32',
'age': 31,
'eyeColor': 'green',
'name': {'first': 'Shana', 'last': 'Long'},
'company': 'MANGLO',
'email': 'shana.long@manglo.us',
'phone': '+1 (926) 405-3105',
'address': '747 Dank Court, Norfolk, Ohio, 1112',
'about': 'Eu pariatur in nisi occaecat enim qui consequat nostrud cupidatat id. ' +
Id: '5642c4c33d4667c4a1fefd99',
index: 0,
guid: '5baf1f1c-7621-41e7-ae7a-f8c6f3199b0f',
isActive: true,
balance: '$1,028.63',
picture: 'http://placehold.it/32x32',
age: 31,
eyeColor: 'green',
name: { first: 'Shana', last: 'Long' },
company: 'MANGLO',
email: 'shana.long@manglo.us',
phone: '+1 (926) 405-3105',
address: '747 Dank Court, Norfolk, Ohio, 1112',
about: 'Eu pariatur in nisi occaecat enim qui consequat nostrud cupidatat id. ' +
'Commodo commodo dolore esse irure minim quis deserunt anim laborum aute deserunt et est. Quis nisi laborum deserunt nisi quis.',
'registered': 'Friday, April 18, 2014 9:56 AM',
'latitude': '74.566613',
'longitude': '-11.660432',
'tags': [7, 'excepteur'],
'range': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
'friends': [3, {'id': 1, 'name': 'Schultz Dyer'}],
'greeting': 'Hello, Shana! You have 5 unread messages.',
'favoriteFruit': 'strawberry'
registered: 'Friday, April 18, 2014 9:56 AM',
latitude: '74.566613',
longitude: '-11.660432',
tags: [7, 'excepteur'],
range: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
friends: [3, { id: 1, name: 'Schultz Dyer' }],
greeting: 'Hello, Shana! You have 5 unread messages.',
favoriteFruit: 'strawberry'
}
function run () {
function run() {
if (end() === true) {
return
}
@@ -132,10 +134,11 @@ describe('The \'multi\' method', () => {
it('results in a execabort #2', () => {
// Check that using monitor with a transactions results in an error
return client.multi().set('foo', 'bar').monitor().exec().then(assert, (err) => {
assert.strictEqual(err.code, 'EXECABORT')
client.end(false)
})
return client.multi().set('foo', 'bar').monitor().exec()
.then(assert, (err) => {
assert.strictEqual(err.code, 'EXECABORT')
client.end(false)
})
})
it('sanity check', (done) => {
@@ -178,7 +181,7 @@ describe('The \'multi\' method', () => {
const multi1 = client.multi()
multi1.set('m1', '123')
multi1.get('m1')
multi1.exec().then(() => (called = true))
multi1.exec().then(() => { called = true })
client.once('ready', () => {
const multi1 = client.multi()
multi1.set('m2', '456')
@@ -199,7 +202,7 @@ describe('The \'multi\' method', () => {
host: 'somewhere',
port: 6379,
family: 'IPv6',
retryStrategy () {}
retryStrategy() {}
})
assert.strictEqual(client._connectionOptions.family, 6)
@@ -334,8 +337,8 @@ describe('The \'multi\' method', () => {
[['hmset', 'multihmset2', 'multibar2', 'multifoo3', 'multibar3', 'test']],
['hmset', ['multihmset', 'multibar', 'multifoo']],
['hmset', arr3],
['hmset', now, {123456789: 'abcdefghij', 'some manner of key': 'a type of value', 'otherTypes': 555}],
['hmset', 'key2', {'0123456789': 'abcdefghij', 'some manner of key': 'a type of value', 'otherTypes': 999}],
['hmset', now, { 123456789: 'abcdefghij', 'some manner of key': 'a type of value', otherTypes: 555 }],
['hmset', 'key2', { '0123456789': 'abcdefghij', 'some manner of key': 'a type of value', otherTypes: 999 }],
['hmset', 'multihmset', ['multibar', 'multibaz']],
['hmset', 'multihmset', ['multibar', 'multibaz']]
])
@@ -343,7 +346,8 @@ describe('The \'multi\' method', () => {
.hmget('key2', arr2)
.hmget(['multihmset2', 'some manner of key', 'multibar3'])
.mget('multifoo2', ['multifoo3', 'multifoo'])
.exec().then((replies) => {
.exec()
.then((replies) => {
assert.strictEqual(arr.length, 3)
assert.strictEqual(arr2.length, 2)
assert.strictEqual(arr3.length, 3)
@@ -376,7 +380,8 @@ describe('The \'multi\' method', () => {
.incr('some')
.incr('keys')
.mget('some', ['keys'])
.exec().then(helper.isDeepEqual(['OK', 11, 21, ['11', '21']]))
.exec()
.then(helper.isDeepEqual(['OK', 11, 21, ['11', '21']]))
})
it('allows an array to be provided indicating multiple operations to perform', () => {
@@ -395,7 +400,8 @@ describe('The \'multi\' method', () => {
things: 'here'
})
.hgetall('multihash')
.exec().then((replies) => {
.exec()
.then((replies) => {
assert.strictEqual('OK', replies[0])
assert.strictEqual(Object.keys(replies[2]).length, 4)
assert.strictEqual('foo', replies[2].a)
@@ -406,28 +412,32 @@ describe('The \'multi\' method', () => {
})
it('reports EXECABORT exceptions when they occur (while queueing)', () => {
return client.multi().config('bar').set('foo').set('bar').exec().then(assert, (err) => {
assert.strictEqual(err.code, 'EXECABORT')
assert(err.message.match(/^EXECABORT/), 'Error message should begin with EXECABORT')
assert.strictEqual(err.errors.length, 2, 'err.errors should have 2 items')
assert.strictEqual(err.errors[0].command, 'SET')
assert.strictEqual(err.errors[0].code, 'ERR')
assert.strictEqual(err.errors[0].position, 1)
assert(/^ERR/.test(err.errors[0].message), 'Actual error message should begin with ERR')
})
return client.multi().config('bar').set('foo').set('bar')
.exec()
.then(assert, (err) => {
assert.strictEqual(err.code, 'EXECABORT')
assert(err.message.match(/^EXECABORT/), 'Error message should begin with EXECABORT')
assert.strictEqual(err.errors.length, 2, 'err.errors should have 2 items')
assert.strictEqual(err.errors[0].command, 'SET')
assert.strictEqual(err.errors[0].code, 'ERR')
assert.strictEqual(err.errors[0].position, 1)
assert(/^ERR/.test(err.errors[0].message), 'Actual error message should begin with ERR')
})
})
it('reports multiple exceptions when they occur (while EXEC is running)', () => {
return client.multi().config('bar').debug('foo').eval('return {err=\'this is an error\'}', 0).exec().then(assert, (err) => {
assert.strictEqual(err.replies.length, 3)
assert.strictEqual(err.replies[0].code, 'ERR')
assert.strictEqual(err.replies[0].command, 'CONFIG')
assert.strictEqual(err.replies[2].code, undefined)
assert.strictEqual(err.replies[2].command, 'EVAL')
assert(/^this is an error/.test(err.replies[2].message))
assert(/^ERR/.test(err.replies[0].message), 'Error message should begin with ERR')
assert(/^ERR/.test(err.replies[1].message), 'Error message should begin with ERR')
})
return client.multi().config('bar').debug('foo').eval('return {err=\'this is an error\'}', 0)
.exec()
.then(assert, (err) => {
assert.strictEqual(err.replies.length, 3)
assert.strictEqual(err.replies[0].code, 'ERR')
assert.strictEqual(err.replies[0].command, 'CONFIG')
assert.strictEqual(err.replies[2].code, undefined)
assert.strictEqual(err.replies[2].command, 'EVAL')
assert(/^this is an error/.test(err.replies[2].message))
assert(/^ERR/.test(err.replies[0].message), 'Error message should begin with ERR')
assert(/^ERR/.test(err.replies[1].message), 'Error message should begin with ERR')
})
})
it('should not use a transaction with execAtomic if no command is used', () => {
@@ -487,16 +497,19 @@ describe('The \'multi\' method', () => {
})
it('indivdual commands work properly with multi', () => {
// Neither of the following work properly in a transactions:
// (This is due to Redis not returning the reply as expected / resulting in undefined behavior)
// (Likely there are more commands that do not work with a transaction)
// Neither of the following work properly in a transactions: (This is
// due to Redis not returning the reply as expected / resulting in
// undefined behavior) (Likely there are more commands that do not
// work with a transaction)
//
// auth => can't be called after a multi command
// monitor => results in faulty return values e.g. multi().monitor().set('foo', 'bar').get('foo')
// returns ['OK, 'OK', 'monitor reply'] instead of ['OK', 'OK', 'bar']
// quit => ends the connection before the exec
// client reply skip|off => results in weird return values. Not sure what exactly happens
// subscribe => enters subscribe mode and this does not work in combination with exec (the same for psubscribe, unsubscribe...)
// auth => can't be called after a multi command monitor => results in
// faulty return values e.g. multi().monitor().set('foo',
// 'bar').get('foo') returns ['OK, 'OK', 'monitor reply'] instead of
// ['OK', 'OK', 'bar'] quit => ends the connection before the exec
// client reply skip|off => results in weird return values. Not sure
// what exactly happens subscribe => enters subscribe mode and this
// does not work in combination with exec (the same for psubscribe,
// unsubscribe...)
//
// Make sure sendCommand is not called
@@ -514,7 +527,10 @@ describe('The \'multi\' method', () => {
return multi.exec().then((res) => {
res[2] = res[2].substr(0, 10)
assert.strictEqual(client.selectedDb, 5)
assert.deepStrictEqual(client.serverInfo.keyspace.db5, { avg_ttl: 0, expires: 0, keys: 1 })
assert.deepStrictEqual(
client.serverInfo.keyspace.db5,
{ avg_ttl: 0, expires: 0, keys: 1 }
)
assert.deepStrictEqual(res, ['OK', 'OK', '# Server\r\n', 'bar'])
return client.flushdb()
})

View File

@@ -1,14 +1,15 @@
'use strict'
const Buffer = require('buffer').Buffer
const { Buffer } = require('buffer')
const assert = require('assert')
const fs = require('fs')
const path = require('path')
const config = require('./lib/config')
const helper = require('./helper')
const fork = require('child_process').fork
const { fork } = require('child_process')
const Errors = require('redis-errors')
const redis = config.redis
const { redis } = config
let client
describe('The nodeRedis client', () => {
@@ -41,7 +42,7 @@ describe('The nodeRedis client', () => {
it('reset the parser while reconnecting (See #1190)', (done) => {
const client = redis.createClient({
retryStrategy () {
retryStrategy() {
return 5
}
})
@@ -113,10 +114,9 @@ describe('The nodeRedis client', () => {
assert.strictEqual(client2.selectedDb, 2)
assert(client.connected)
assert(!client2.connected)
for (const elem in client._options) {
if (client._options.hasOwnProperty(elem)) {
assert.strictEqual(client2._options[elem], client._options[elem])
}
const keys = Object.keys(client._options)
for (let i = 0; i < keys.length; i++) {
assert.strictEqual(client2._options[keys[i]], client._options[keys[i]])
}
client2.on('error', (err) => {
assert.strictEqual(err.message, 'Connection forcefully ended and command aborted.')
@@ -140,11 +140,10 @@ describe('The nodeRedis client', () => {
assert.strictEqual(client._options.noReadyCheck, undefined)
assert.strictEqual(client2._options.noReadyCheck, true)
assert.notDeepEqual(client._options, client2._options)
for (const elem in client._options) {
if (client._options.hasOwnProperty(elem)) {
if (elem !== 'noReadyCheck') {
assert.strictEqual(client2._options[elem], client._options[elem])
}
const keys = Object.keys(client._options)
for (let i = 0; i < keys.length; i++) {
if (keys[i] !== 'noReadyCheck') {
assert.strictEqual(client2._options[keys[i]], client._options[keys[i]])
}
}
client2.on('ready', () => {
@@ -190,12 +189,14 @@ describe('The nodeRedis client', () => {
})
it('using multi with sendCommand should work as individual command instead of using the internal multi', () => {
// This is necessary to keep backwards compatibility and it is the only way to handle multi as you want in nodeRedis
// This is necessary to keep backwards compatibility and it is the
// only way to handle multi as you want in nodeRedis
client.sendCommand('multi')
client.sendCommand('set', ['foo', 'bar']).then(helper.isString('QUEUED'))
client.get('foo')
// exec is not manipulated if not fired by the individual multi command
// As the multi command is handled individually by the user he also has to handle the return value
// exec is not manipulated if not fired by the individual multi
// command As the multi command is handled individually by the user
// he also has to handle the return value
return client.exec().then(helper.isDeepEqual(['OK', 'bar']))
})
@@ -205,7 +206,8 @@ describe('The nodeRedis client', () => {
client.sendCommand('set', args).then(helper.isString('QUEUED'))
assert.deepStrictEqual(args, ['test', 'bla']) // Check args manipulation
client.get('test').then(helper.isString('QUEUED'))
// As the multi command is handled individually by the user he also has to handle the return value
// As the multi command is handled individually by the user he also
// has to handle the return value
return client.exec().then(helper.isDeepEqual(['OK', 'bla']))
})
@@ -245,13 +247,15 @@ describe('The nodeRedis client', () => {
client.sendCommand('set', args).then(helper.isString('QUEUED'))
assert.deepStrictEqual(args, ['test', 'bla']) // Check args manipulation
client.get('test').then(helper.isString('QUEUED'))
// As the multi command is handled individually by the user he also has to handle the return value
// As the multi command is handled individually by the user he also
// has to handle the return value
return client.exec().then(helper.isDeepEqual(['OK', 'bla']))
})
it('the args array may contain a arbitrary number of arguments', () => {
client.sendCommand('mset', ['foo', 1, 'bar', 2, 'baz', 3]).then(helper.isString('OK'))
// As the multi command is handled individually by the user he also has to handle the return value
// As the multi command is handled individually by the user he also
// has to handle the return value
return client.mget(['foo', 'bar', 'baz']).then(helper.isDeepEqual(['1', '2', '3']))
})
@@ -340,8 +344,8 @@ describe('The nodeRedis client', () => {
describe('when redis closes unexpectedly', () => {
it('reconnects and can retrieve the pre-existing data', (done) => {
client.on('reconnecting', function onRecon (params) {
client.on('connect', function onConnect () {
client.on('reconnecting', function onRecon(params) {
client.on('connect', function onConnect() {
const end = helper.callFuncAfter(() => {
client.removeListener('connect', onConnect)
client.removeListener('reconnecting', onRecon)
@@ -365,8 +369,8 @@ describe('The nodeRedis client', () => {
})
it('reconnects properly when monitoring', (done) => {
client.on('reconnecting', function onRecon (params) {
client.on('ready', function onReady () {
client.on('reconnecting', function onRecon(params) {
client.on('ready', function onReady() {
assert.strictEqual(client._monitoring, true, 'monitoring after reconnect')
client.removeListener('ready', onReady)
client.removeListener('reconnecting', onRecon)
@@ -502,7 +506,8 @@ describe('The nodeRedis client', () => {
assert.strictEqual(err.message, 'Protocol error, got "a" as reply type byte. Please report this.')
assert.strictEqual(err, error)
assert(err instanceof redis.ParserError)
// After the hard failure work properly again. The set should have been processed properly too
// After the hard failure work properly again. The set should have
// been processed properly too
client.get('foo').then(helper.isString('bar')).then(done)
})
client.once('ready', () => {
@@ -512,9 +517,9 @@ describe('The nodeRedis client', () => {
assert(err instanceof redis.InterruptError)
error = err.origin
})
// Make sure we call execute out of the reply.
// Ready is called in a reply.
// Fail the set answer. Has no corresponding command obj and will therefore land in the error handler and set
// Make sure we call execute out of the reply. Ready is called in a
// reply. Fail the set answer. Has no corresponding command obj and
// will therefore land in the error handler and set
process.nextTick(() => client._replyParser.execute(Buffer.from('a*1\r*1\r$1`zasd\r\na')))
})
})
@@ -545,7 +550,7 @@ describe('The nodeRedis client', () => {
it('enqueues operation and keep the queue while trying to reconnect', (done) => {
client = redis.createClient(9999, null, {
retryStrategy (options) {
retryStrategy(options) {
if (options.attempt < 4) {
return 50
}
@@ -587,6 +592,7 @@ describe('The nodeRedis client', () => {
})
it('flushes the command queue if connection is lost', (done) => {
const end = helper.callFuncAfter(done, 2)
client = redis.createClient()
client.once('ready', () => {
@@ -607,8 +613,6 @@ describe('The nodeRedis client', () => {
assert.strictEqual(client.commandQueue.length, 15)
helper.killConnection(client)
})
const end = helper.callFuncAfter(done, 2)
client.on('error', (err) => {
assert.strictEqual(err.code, 'ECONNREFUSED')
assert.strictEqual(err.errno, 'ECONNREFUSED')

View File

@@ -3,7 +3,8 @@
const assert = require('assert')
const config = require('./lib/config')
const helper = require('./helper')
const redis = config.redis
const { redis } = config
describe('prefix key names', () => {
helper.allTests((ip, args) => {

View File

@@ -1,10 +1,11 @@
'use strict'
const Buffer = require('buffer').Buffer
const { Buffer } = require('buffer')
const assert = require('assert')
const config = require('./lib/config')
const helper = require('./helper')
const redis = config.redis
const { redis } = config
describe('publish/subscribe', () => {
helper.allTests((ip, args) => {
@@ -285,7 +286,7 @@ describe('publish/subscribe', () => {
})
it('unsubscribes, subscribes, unsubscribes... single and multiple entries mixed', (done) => {
function subscribe (channels) {
function subscribe(channels) {
sub.unsubscribe().then(helper.isNull)
sub.subscribe(channels).then(helper.isNull)
}
@@ -313,7 +314,7 @@ describe('publish/subscribe', () => {
})
it('unsubscribes, subscribes, unsubscribes... single and multiple entries mixed. Without concrete channels', (done) => {
function subscribe (channels) {
function subscribe(channels) {
sub.unsubscribe(channels)
sub.unsubscribe(channels)
sub.subscribe(channels)
@@ -342,7 +343,7 @@ describe('publish/subscribe', () => {
})
it('unsubscribes, subscribes, unsubscribes... with pattern matching', (done) => {
function subscribe (channels, callback) {
function subscribe(channels, callback) {
sub.punsubscribe('prefix:*').then(helper.isNull)
sub.psubscribe(channels).then(callback)
}
@@ -461,7 +462,7 @@ describe('publish/subscribe', () => {
const end = helper.callFuncAfter(done, 5)
const data = Array(10000).join('äüs^öéÉÉ`e')
sub.set('foo', data).then(() => {
sub.get('foo').then((res) => assert.strictEqual(typeof res, 'string'))
sub.get('foo').then(res => assert.strictEqual(typeof res, 'string'))
sub._stream.once('data', () => {
assert.strictEqual(sub._messageBuffers, false)
assert.strictEqual(sub.shouldBuffer, false)
@@ -536,7 +537,7 @@ describe('publish/subscribe', () => {
it('should not publish a message multiple times per command', (done) => {
const published = {}
function subscribe (message) {
function subscribe(message) {
sub.removeAllListeners('subscribe')
sub.removeAllListeners('message')
sub.removeAllListeners('unsubscribe')
@@ -586,7 +587,8 @@ describe('publish/subscribe', () => {
.psubscribe(['pattern:*'])
.punsubscribe('unknown*')
.punsubscribe(['pattern:*'])
.exec().then(() => Promise.all([
.exec()
.then(() => Promise.all([
sub.client('kill', ['type', 'pubsub']),
sub.psubscribe('*'),
sub.punsubscribe('pa*'),

View File

@@ -3,9 +3,10 @@
const assert = require('assert')
const config = require('./lib/config')
const helper = require('./helper')
const redis = config.redis
// TODO: Fix redis process spawn on windows
const { redis } = config
// TODO: Fix redis process spawn on windows
if (process.platform !== 'win32') {
describe('rename commands', () => {
before((done) => {

View File

@@ -1,10 +1,11 @@
'use strict'
const Buffer = require('buffer').Buffer
const { Buffer } = require('buffer')
const assert = require('assert')
const config = require('./lib/config')
const helper = require('./helper')
const redis = config.redis
const { redis } = config
describe('returnBuffers', () => {
helper.allTests((ip, basicArgs) => {
@@ -64,7 +65,8 @@ describe('returnBuffers', () => {
.hget(Buffer.from('hash key 2'), 'key 1')
.hget('hash key 2', Buffer.from('key 2'))
.hget('hash key 2', 'key 2')
.exec().then((reply) => {
.exec()
.then((reply) => {
assert.strictEqual(4, reply.length)
assert.strictEqual('<Buffer 76 61 6c 20 31>', reply[0].inspect())
assert.strictEqual(true, Buffer.isBuffer(reply[1]))
@@ -84,7 +86,8 @@ describe('returnBuffers', () => {
.hget(Buffer.from('hash key 2'), 'key 1')
.hget('hash key 2', Buffer.from('key 2'))
.hget('hash key 2', 'key 2')
.exec().then((reply) => {
.exec()
.then((reply) => {
assert.strictEqual(4, reply.length)
assert.strictEqual('<Buffer 76 61 6c 20 31>', reply[0].inspect())
assert.strictEqual(true, Buffer.isBuffer(reply[1]))

View File

@@ -5,13 +5,14 @@ const config = require('./lib/config')
const fs = require('fs')
const helper = require('./helper')
const path = require('path')
const redis = config.redis
const { redis } = config
const utils = require('../lib/utils')
const tlsOptions = {
servername: 'redis.js.org',
rejectUnauthorized: true,
ca: [ String(fs.readFileSync(path.resolve(__dirname, './conf/redis.js.org.cert'))) ]
ca: [String(fs.readFileSync(path.resolve(__dirname, './conf/redis.js.org.cert')))]
}
const tlsPort = 6380
@@ -109,7 +110,7 @@ describe('TLS connection tests', () => {
it('fails to connect because the cert is not correct', function () {
if (skip) this.skip()
const faultyCert = utils.clone(tlsOptions)
faultyCert.ca = [ String(fs.readFileSync(path.resolve(__dirname, './conf/faulty.cert'))) ]
faultyCert.ca = [String(fs.readFileSync(path.resolve(__dirname, './conf/faulty.cert')))]
client = redis.createClient({
host: 'localhost',
connectTimeout: 1000,

View File

@@ -9,7 +9,7 @@ describe('createClient options', () => {
it('pass the options in the second parameter after a port', () => {
const options = unifyOptions(1234, {
option1: true,
option2 () {}
option2() {}
})
assert.strictEqual(Object.keys(options).length, 4)
assert(options.option1)
@@ -21,7 +21,7 @@ describe('createClient options', () => {
it('pass the options in the third parameter after a port and host being set to null', () => {
const options = unifyOptions(1234, null, {
option1: true,
option2 () {}
option2() {}
})
assert.strictEqual(Object.keys(options).length, 4)
assert(options.option1)
@@ -33,7 +33,7 @@ describe('createClient options', () => {
it('pass the options in the third parameter after a port and host being set to undefined', () => {
const options = unifyOptions(1234, undefined, {
option1: true,
option2 () {}
option2() {}
})
assert.strictEqual(Object.keys(options).length, 4)
assert(options.option1)
@@ -45,7 +45,7 @@ describe('createClient options', () => {
it('pass the options in the third parameter after a port and host', () => {
const options = unifyOptions('1234', 'localhost', {
option1: true,
option2 () {}
option2() {}
})
assert.strictEqual(Object.keys(options).length, 4)
assert(options.option1)
@@ -68,7 +68,7 @@ describe('createClient options', () => {
it('pass the options in the second parameter after a port', () => {
const options = unifyOptions('/tmp/redis.sock', {
option1: true,
option2 () {},
option2() {},
option3: [1, 2, 3]
})
assert.strictEqual(Object.keys(options).length, 4)
@@ -81,7 +81,7 @@ describe('createClient options', () => {
it('pass the options in the third parameter after a port and host being set to null', () => {
const options = unifyOptions('/tmp/redis.sock', null, {
option1: true,
option2 () {}
option2() {}
})
assert.strictEqual(Object.keys(options).length, 3)
assert(options.option1)
@@ -120,7 +120,8 @@ describe('createClient options', () => {
option: [1, 2, 3]
})
unhookIntercept()
assert.strictEqual(text,
assert.strictEqual(
text,
'nodeRedis: WARNING: You passed the db option twice!\n' +
'nodeRedis: WARNING: You passed the port option twice!\n' +
'nodeRedis: WARNING: You passed the password option twice!\n'

View File

@@ -6,10 +6,10 @@ const intercept = require('intercept-stdout')
const utils = require('../lib/utils')
describe('utils.js', () => {
describe('print helper', function () {
it('callback with reply', function () {
var text = ''
const unhookIntercept = intercept(function (data) {
describe('print helper', () => {
it('callback with reply', () => {
let text = ''
const unhookIntercept = intercept((data) => {
text += data
return ''
})
@@ -18,9 +18,9 @@ describe('utils.js', () => {
assert.strictEqual(text, 'Reply: abc\n')
})
it('callback with error', function () {
var text = ''
const unhookIntercept = intercept(function (data) {
it('callback with error', () => {
let text = ''
const unhookIntercept = intercept((data) => {
text += data
return ''
})
@@ -37,7 +37,7 @@ describe('utils.js', () => {
'i\'m special': true
}],
number: 5,
fn: function noop () {}
fn: function noop() {}
}
const clone = utils.clone(obj)
assert.deepStrictEqual(clone, obj)
@@ -73,7 +73,7 @@ describe('utils.js', () => {
}
const createCommandObj = function () {
return {
callback (err, res) {
callback(err, res) {
if (err) errCount++
else resCount++
}