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: refactor codebase to promises
This commit is contained in:
@@ -13,11 +13,9 @@ describe('The \'client\' method', () => {
|
||||
describe(`using ${ip}`, () => {
|
||||
let client
|
||||
|
||||
beforeEach((done) => {
|
||||
beforeEach(() => {
|
||||
client = redis.createClient.apply(null, args)
|
||||
client.once('ready', () => {
|
||||
client.flushdb(done)
|
||||
})
|
||||
return client.flushdb()
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
@@ -25,93 +23,93 @@ describe('The \'client\' method', () => {
|
||||
})
|
||||
|
||||
describe('list', () => {
|
||||
it('lists connected clients', (done) => {
|
||||
client.client('LIST', helper.match(pattern, done))
|
||||
it('lists connected clients', () => {
|
||||
return client.client('LIST').then(helper.match(pattern))
|
||||
})
|
||||
|
||||
it('lists connected clients when invoked with multi\'s chaining syntax', (done) => {
|
||||
client.multi().client('list', helper.isType.string()).exec(helper.match(pattern, done))
|
||||
it('lists connected clients when invoked with multi\'s chaining syntax', () => {
|
||||
return client.multi().client('list').exec().then(helper.match(pattern))
|
||||
})
|
||||
|
||||
it('lists connected clients when invoked with array syntax on client', (done) => {
|
||||
client.multi().client(['list']).exec(helper.match(pattern, done))
|
||||
it('lists connected clients when invoked with array syntax on client', () => {
|
||||
return client.multi().client(['list']).exec().then(helper.match(pattern))
|
||||
})
|
||||
|
||||
it('lists connected clients when invoked with multi\'s array syntax', (done) => {
|
||||
client.multi([
|
||||
it('lists connected clients when invoked with multi\'s array syntax', () => {
|
||||
return client.multi([
|
||||
['client', 'list']
|
||||
]).exec(helper.match(pattern, done))
|
||||
]).exec().then(helper.match(pattern))
|
||||
})
|
||||
})
|
||||
|
||||
describe('reply', () => {
|
||||
describe('as normal command', () => {
|
||||
it('on', function (done) {
|
||||
it('on', function () {
|
||||
helper.serverVersionAtLeast.call(this, client, [3, 2, 0])
|
||||
assert.strictEqual(client.reply, 'ON')
|
||||
client.client('reply', 'on', helper.isString('OK'))
|
||||
const promises = [client.client('reply', 'on').then(helper.isString('OK'))]
|
||||
assert.strictEqual(client.reply, 'ON')
|
||||
client.set('foo', 'bar', done)
|
||||
promises.push(client.set('foo', 'bar'))
|
||||
return Promise.all(promises)
|
||||
})
|
||||
|
||||
it('off', function (done) {
|
||||
it('off', function () {
|
||||
helper.serverVersionAtLeast.call(this, client, [3, 2, 0])
|
||||
assert.strictEqual(client.reply, 'ON')
|
||||
client.client(Buffer.from('REPLY'), 'OFF', helper.isUndefined())
|
||||
const promises = [client.client(Buffer.from('REPLY'), 'OFF').then(helper.isUndefined())]
|
||||
assert.strictEqual(client.reply, 'OFF')
|
||||
client.set('foo', 'bar', helper.isUndefined(done))
|
||||
promises.push(client.set('foo', 'bar').then(helper.isUndefined()))
|
||||
return Promise.all(promises)
|
||||
})
|
||||
|
||||
it('skip', function (done) {
|
||||
it('skip', function () {
|
||||
helper.serverVersionAtLeast.call(this, client, [3, 2, 0])
|
||||
assert.strictEqual(client.reply, 'ON')
|
||||
client.client('REPLY', Buffer.from('SKIP'), helper.isUndefined())
|
||||
const promises = [client.client('REPLY', Buffer.from('SKIP')).then(helper.isUndefined())]
|
||||
assert.strictEqual(client.reply, 'SKIP_ONE_MORE')
|
||||
client.set('foo', 'bar', helper.isUndefined())
|
||||
client.get('foo', helper.isString('bar', done))
|
||||
promises.push(client.set('foo', 'bar').then(helper.isUndefined()))
|
||||
promises.push(client.get('foo').then(helper.isString('bar')))
|
||||
return Promise.all(promises)
|
||||
})
|
||||
})
|
||||
|
||||
describe('in a batch context', () => {
|
||||
it('on', function (done) {
|
||||
it('on', function () {
|
||||
helper.serverVersionAtLeast.call(this, client, [3, 2, 0])
|
||||
const batch = client.batch()
|
||||
assert.strictEqual(client.reply, 'ON')
|
||||
batch.client('reply', 'on', helper.isString('OK'))
|
||||
batch.client('reply', 'on')
|
||||
assert.strictEqual(client.reply, 'ON')
|
||||
batch.set('foo', 'bar')
|
||||
batch.exec((err, res) => {
|
||||
assert.deepEqual(res, ['OK', 'OK'])
|
||||
done(err)
|
||||
})
|
||||
return batch.exec().then(helper.isDeepEqual(['OK', 'OK']))
|
||||
})
|
||||
|
||||
it('off', function (done) {
|
||||
it('off', function () {
|
||||
helper.serverVersionAtLeast.call(this, client, [3, 2, 0])
|
||||
const 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((err, res) => {
|
||||
batch.client(Buffer.from('REPLY'), Buffer.from('OFF'))
|
||||
batch.get('hello')
|
||||
batch.get('hello')
|
||||
return batch.exec().then((res) => {
|
||||
assert.strictEqual(client.reply, 'OFF')
|
||||
assert.deepEqual(res, ['OK', undefined, undefined])
|
||||
done(err)
|
||||
assert.deepStrictEqual(res, ['OK', undefined, undefined, undefined])
|
||||
})
|
||||
})
|
||||
|
||||
it('skip', function (done) {
|
||||
it('skip', function () {
|
||||
helper.serverVersionAtLeast.call(this, client, [3, 2, 0])
|
||||
assert.strictEqual(client.reply, 'ON')
|
||||
client.batch()
|
||||
return client.batch()
|
||||
.set('hello', 'world')
|
||||
.client('REPLY', 'SKIP', helper.isUndefined())
|
||||
.set('foo', 'bar', helper.isUndefined())
|
||||
.client('REPLY', 'SKIP')
|
||||
.set('foo', 'bar')
|
||||
.get('foo')
|
||||
.exec((err, res) => {
|
||||
.exec()
|
||||
.then((res) => {
|
||||
assert.strictEqual(client.reply, 'ON')
|
||||
assert.deepEqual(res, ['OK', undefined, undefined, 'bar'])
|
||||
done(err)
|
||||
assert.deepStrictEqual(res, ['OK', undefined, undefined, 'bar'])
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -122,25 +120,23 @@ describe('The \'client\' method', () => {
|
||||
|
||||
beforeEach((done) => {
|
||||
client2 = redis.createClient.apply(null, args)
|
||||
client2.once('ready', () => {
|
||||
done()
|
||||
})
|
||||
client2.once('ready', done)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
client2.end(true)
|
||||
})
|
||||
|
||||
it('sets the name', (done) => {
|
||||
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
|
||||
const 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', helper.isString('MARTIN', end))
|
||||
client.client('getname', helper.isString('RUTH', end))
|
||||
return Promise.all([
|
||||
client.client('setname', 'RUTH'),
|
||||
client2.client('setname', ['RENEE']).then(helper.isString('OK')),
|
||||
client2.client(['setname', 'MARTIN']).then(helper.isString('OK')),
|
||||
client2.client('getname').then(helper.isString('MARTIN')),
|
||||
client.client('getname').then(helper.isString('RUTH'))
|
||||
])
|
||||
})
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user