Skip to content

Commit

Permalink
ISS-245 | accept namespace as array
Browse files Browse the repository at this point in the history
Signed-off-by: a.kuzmenko <[email protected]>
  • Loading branch information
witem committed Jul 25, 2018
1 parent d3477e4 commit ded1e60
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions __tests__/core/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
6 changes: 5 additions & 1 deletion lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(':')
}
Expand Down

0 comments on commit ded1e60

Please sign in to comment.