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:
@@ -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(() => {
|
||||
|
Reference in New Issue
Block a user