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

chore: refactor codebase to promises

This commit is contained in:
Ruben Bridgewater
2017-05-19 06:14:29 +02:00
parent b2613b2270
commit 6be5575c5b
85 changed files with 2081 additions and 3690 deletions

View File

@@ -18,8 +18,8 @@ if (process.platform !== 'win32') {
describe(`using ${ip}`, () => {
let client = null
beforeEach((done) => {
if (helper.redisProcess().spawnFailed()) return done()
beforeEach(() => {
if (helper.redisProcess().spawnFailed()) return
client = redis.createClient({
renameCommands: {
set: '807081f5afa96845a02816a28b7258c3',
@@ -27,9 +27,7 @@ if (process.platform !== 'win32') {
}
})
client.on('ready', () => {
client.flushdb(done)
})
return client.flushdb()
})
afterEach(() => {
@@ -37,75 +35,56 @@ if (process.platform !== 'win32') {
client.end(true)
})
it('allows to use renamed functions', function (done) {
it('allows to use renamed functions', function () {
if (helper.redisProcess().spawnFailed()) this.skip()
client.set('key', 'value', helper.isString('OK'))
client.set('key', 'value').then(helper.isString('OK'))
client.get('key', (err, reply) => {
client.get('key').then(helper.fail).catch((err) => {
assert.strictEqual(err.message, 'ERR unknown command \'get\'')
assert.strictEqual(err.command, 'GET')
assert.strictEqual(reply, undefined)
})
client.getrange('key', 1, -1, (err, reply) => {
assert.strictEqual(reply, 'alue')
assert.strictEqual(err, null)
done()
})
return client.getrange('key', 1, -1).then(helper.isString('alue'))
})
it('should also work with batch', function (done) {
it('should also work with batch', function () {
if (helper.redisProcess().spawnFailed()) this.skip()
client.batch([['set', 'key', 'value']]).exec(helper.isDeepEqual(['OK']))
const batch = client.batch()
batch.getrange('key', 1, -1)
batch.exec((err, res) => {
assert(!err)
assert.strictEqual(res.length, 1)
assert.strictEqual(res[0], 'alue')
done()
})
return batch.exec().then(helper.isDeepEqual(['alue']))
})
it('should also work with multi', function (done) {
it('should also work with multi', function () {
if (helper.redisProcess().spawnFailed()) this.skip()
client.multi([['set', 'key', 'value']]).exec(helper.isDeepEqual(['OK']))
const multi = client.multi()
multi.getrange('key', 1, -1)
multi.exec((err, res) => {
assert(!err)
assert.strictEqual(res.length, 1)
assert.strictEqual(res[0], 'alue')
done()
})
return multi.exec().then(helper.isDeepEqual(['alue']))
})
it('should also work with multi and abort transaction', function (done) {
it('should also work with multi and abort transaction', function () {
if (helper.redisProcess().spawnFailed()) this.skip()
const multi = client.multi()
multi.get('key')
multi.getrange('key', 1, -1, (err, reply) => {
assert.strictEqual(reply, 'alue')
assert.strictEqual(err, null)
})
multi.exec((err, res) => {
multi.getrange('key', 1, -1)
return multi.exec().then(helper.fail).catch((err) => {
assert(err)
assert.strictEqual(err.message, 'EXECABORT Transaction discarded because of previous errors.')
assert.strictEqual(err.errors[0].message, 'ERR unknown command \'get\'')
assert.strictEqual(err.errors[0].command, 'GET')
assert.strictEqual(err.code, 'EXECABORT')
assert.strictEqual(err.errors[0].code, 'ERR')
done()
})
})
it('should also work prefixed commands', function (done) {
it('should also work prefixed commands', function () {
if (helper.redisProcess().spawnFailed()) this.skip()
client.end(true)
@@ -116,11 +95,7 @@ if (process.platform !== 'win32') {
prefix: 'baz'
})
client.set('foo', 'bar')
client.keys('*', (err, reply) => {
assert.strictEqual(reply[0], 'bazfoo')
assert.strictEqual(err, null)
done()
})
return client.keys('*').then(helper.isDeepEqual(['bazfoo']))
})
})
})