diff --git a/README.md b/README.md index b493c9b6..0ab9c18c 100644 --- a/README.md +++ b/README.md @@ -141,7 +141,7 @@ var connectionDetails = { password: "", port: 6379, database: 0, - namespace: "resque", + namespace: "resque", // Also allow array of strings } var worker = new NodeResque.Worker({connection: connectionDetails, queues: 'math'}, jobs); diff --git a/__tests__/core/connection.js b/__tests__/core/connection.js index 40afa468..656bcc7b 100644 --- a/__tests__/core/connection.js +++ b/__tests__/core/connection.js @@ -93,6 +93,14 @@ describe('connection', () => { expect(prefixedConnection.key('thing')).toBe(`customNamespace:thing`) }) + test('keys built with a array namespace are correct', () => { + connection.options.namespace = ['custom', 'namespace'] + expect(connection.key('thing')).toBe(`custom:namespace:thing`) + + prefixedConnection.options.namespace = ['custom', 'namespace'] + expect(prefixedConnection.key('thing')).toBe(`custom:namespace:thing`) + }) + test('will properly build namespace strings dynamically', async () => { connection.options.namespace = specHelper.namespace expect(connection.key('thing')).toBe(specHelper.namespace + ':thing') diff --git a/lib/connection.js b/lib/connection.js index bd1de932..1420ccb1 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -86,7 +86,11 @@ class Connection extends EventEmitter { key () { let args args = (arguments.length >= 1 ? [].slice.call(arguments, 0) : []) - args.unshift(this.options.namespace) + if (Array.isArray(this.options.namespace)) { + args.unshift(...this.options.namespace) + } else { + args.unshift(this.options.namespace) + } args = args.filter((e) => { return String(e).trim() }) return args.join(':') }