From ded1e606b82ff6e800d65cf28713acf04a03ded6 Mon Sep 17 00:00:00 2001 From: "a.kuzmenko" Date: Wed, 25 Jul 2018 10:52:19 +0300 Subject: [PATCH] ISS-245 | accept namespace as array Signed-off-by: a.kuzmenko --- README.md | 2 +- __tests__/core/connection.js | 8 ++++++++ lib/connection.js | 6 +++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 93cbaa98..933cdf33 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(':') }