1
0
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:
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

@@ -1,6 +1,5 @@
'use strict'
const assert = require('assert')
const config = require('../lib/config')
const helper = require('../helper')
const redis = config.redis
@@ -11,100 +10,57 @@ describe('The \'hmset\' method', () => {
let client
const hash = 'test hash'
beforeEach((done) => {
beforeEach(() => {
client = redis.createClient.apply(null, args)
client.once('ready', () => {
client.flushdb(done)
})
return client.flushdb()
})
it('handles redis-style syntax', (done) => {
client.hmset(hash, '0123456789', 'abcdefghij', 'some manner of key', 'a type of value', 'otherTypes', 555, helper.isString('OK'))
client.hgetall(hash, (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', () => {
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'
}))
})
it('handles object-style syntax', (done) => {
client.hmset(hash, {'0123456789': 'abcdefghij', 'some manner of key': 'a type of value', 'otherTypes': 555}, helper.isString('OK'))
client.hgetall(hash, (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', () => {
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'
}))
})
it('handles object-style syntax and the key being a number', (done) => {
client.hmset(231232, {'0123456789': 'abcdefghij', 'some manner of key': 'a type of value', 'otherTypes': 555}, undefined)
client.hgetall(231232, (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 and the key being a number', () => {
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'
}))
})
it('allows a numeric key', (done) => {
client.hmset(hash, 99, 'banana', helper.isString('OK'))
client.hgetall(hash, (err, obj) => {
assert.strictEqual(obj['99'], 'banana')
return done(err)
})
it('allows a numeric key', () => {
client.hmset(hash, 99, 'banana').then(helper.isString('OK'))
return client.hgetall(hash).then(helper.isDeepEqual({ 99: 'banana' }))
})
it('allows a numeric key without callback', (done) => {
client.hmset(hash, 99, 'banana', 'test', 25)
client.hgetall(hash, (err, obj) => {
assert.strictEqual(obj['99'], 'banana')
assert.strictEqual(obj.test, '25')
return done(err)
})
it('allows an array', () => {
client.hmset([hash, 99, 'banana', 'test', 25]).then(helper.isString('OK'))
return client.hgetall(hash).then(helper.isDeepEqual({
99: 'banana',
test: '25'
}))
})
it('allows an array without callback', (done) => {
client.hmset([hash, 99, 'banana', 'test', 25])
client.hgetall(hash, (err, obj) => {
assert.strictEqual(obj['99'], 'banana')
assert.strictEqual(obj.test, '25')
return done(err)
})
})
it('allows an array and a callback', (done) => {
client.hmset([hash, 99, 'banana', 'test', 25], helper.isString('OK'))
client.hgetall(hash, (err, obj) => {
assert.strictEqual(obj['99'], 'banana')
assert.strictEqual(obj.test, '25')
return done(err)
})
})
it('allows a key plus array without callback', (done) => {
client.hmset(hash, [99, 'banana', 'test', 25])
client.hgetall(hash, (err, obj) => {
assert.strictEqual(obj['99'], 'banana')
assert.strictEqual(obj.test, '25')
return done(err)
})
})
it('allows a key plus array and a callback', (done) => {
client.hmset(hash, [99, 'banana', 'test', 25], helper.isString('OK'))
client.hgetall(hash, (err, obj) => {
assert.strictEqual(obj['99'], 'banana')
assert.strictEqual(obj.test, '25')
return done(err)
})
})
it('handles object-style syntax without callback', (done) => {
client.hmset(hash, {'0123456789': 'abcdefghij', 'some manner of key': 'a type of value'})
client.hgetall(hash, (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', () => {
client.hmset(hash, [99, 'banana', 'test', 25]).then(helper.isString('OK'))
return client.hgetall(hash).then(helper.isDeepEqual({
99: 'banana',
test: '25'
}))
})
afterEach(() => {