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

feat: accept Map and Set and flatten arguments

This commit is contained in:
Ruben Bridgewater
2017-05-26 10:30:27 +02:00
parent 4182059b7c
commit 6ea202132b
9 changed files with 224 additions and 332 deletions

View File

@@ -209,15 +209,17 @@ if (process.platform !== 'win32') {
client.set('foo', 'bar')
client.subscribe('somechannel', 'another channel').then(() => {
assert.strictEqual(client.pubSubMode, 1)
client.get('foo').catch((err) => {
assert(/ERR only \(P\)SUBSCRIBE \/ \(P\)UNSUBSCRIBE/.test(err.message))
done()
client.once('ready', () => {
client.get('foo').catch((err) => {
assert(/ERR only \(P\)SUBSCRIBE \/ \(P\)UNSUBSCRIBE/.test(err.message))
done()
})
})
})
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(() => { // Make sure all commands were properly processed already
client.ping().then(() => { // Make sure all commands were properly processed already
client.stream.destroy()
})
})

View File

@@ -152,12 +152,12 @@ describe('The \'batch\' method', () => {
['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', 'batchhmset', ['batchbar', 'batchbaz']],
['hmset', 'batchhmset', ['batchbar', 'batchbaz']]
['hmset', new Set(['batchhmset', ['batchbar', 'batchbaz']])],
['hmset', ['batchhmset'], new Map([['batchbar', 'batchbaz']])]
])
.hmget(now, 123456789, 'otherTypes')
.hmget(now, 123456789, ['otherTypes'])
.hmget('key2', arr2)
.hmget(['batchhmset2', 'some manner of key', 'batchbar3'])
.hmget(['batchhmset2', ['some manner of key', 'batchbar3']])
.mget('batchfoo2', ['batchfoo3', 'batchfoo'])
.exec().then((replies) => {
assert.strictEqual(arr.length, 3)

View File

@@ -16,15 +16,15 @@ describe('The nodeRedis client', () => {
// Therefor individual commands always have to be handled in both cases
fs.readFile(path.resolve(__dirname, '../lib/individualCommands.js'), 'utf8', (err, data) => {
assert.strictEqual(err, null)
const clientPrototype = data.match(/(\n| = )RedisClient\.prototype.[a-zA-Z_]+/g)
const multiPrototype = data.match(/(\n| = )Multi\.prototype\.[a-zA-Z_]+/g)
const clientPrototype = data.match(/(\n| = )RedisClient\.prototype.[a-z][a-zA-Z_]+/g)
const multiPrototype = data.match(/(\n| = )Multi\.prototype\.[a-z][a-zA-Z_]+/g)
// Check that every entry RedisClient entry has a correspondent Multi entry
assert.strictEqual(clientPrototype.filter((entry) => {
return multiPrototype.indexOf(entry.replace('RedisClient', 'Multi')) === -1
}).length, 3) // multi and batch are included too
assert.strictEqual(clientPrototype.length, multiPrototype.length + 3)
return !multiPrototype.includes(entry.replace('RedisClient', 'Multi'))
}).length, 2) // multi and batch are included too
assert.strictEqual(clientPrototype.length, multiPrototype.length + 2)
// Check that all entries exist only in lowercase variants
assert.strictEqual(data.match(/(\n| = )RedisClient\.prototype.[a-zA-Z_]+/g).length, clientPrototype.length)
assert.strictEqual(data.match(/(\n| = )RedisClient\.prototype.[a-z][a-zA-Z_]+/g).length, clientPrototype.length)
done()
})
})
@@ -135,16 +135,8 @@ describe('The nodeRedis client', () => {
describe('big data', () => {
// Check if the fast mode for big strings is working correct
it('safe strings that are bigger than 30000 characters', () => {
let str = 'foo ಠ_ಠ bar '
while (str.length < 111111) {
str += str
}
client.set('foo', str)
return client.get('foo').then(helper.isString(str))
})
it('safe strings that are bigger than 30000 characters with multi', () => {
// TODO: Evaluate if this is still necessary after the refactoring
it.skip('safe strings that are bigger than 30000 characters with multi', () => {
let str = 'foo ಠ_ಠ bar '
while (str.length < 111111) {
str += str

View File

@@ -506,7 +506,7 @@ describe('publish/subscribe', () => {
})
it('executes when punsubscribe is called and there are no subscriptions', () => {
return pub.batch().punsubscribe(helper.isDeepEqual([0, []])).exec()
return pub.batch().punsubscribe().exec().then(helper.isDeepEqual([[0, []]]))
})
})