Skip to content

Commit 2a29569

Browse files
authored
feat: pass clientName to createClient function
Overrides the options.redis settings for clientName for creating a new client
1 parent 6171f1a commit 2a29569

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

PATTERNS.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,15 @@ const client = new Redis(REDIS_URL);
8282
const subscriber = new Redis(REDIS_URL);
8383

8484
const opts = {
85-
createClient: function (type) {
85+
// redisOpts here will contain at least a property of connectionName which will identify the queue based on its name
86+
createClient: function (type, redisOpts) {
8687
switch (type) {
8788
case 'client':
8889
return client;
8990
case 'subscriber':
9091
return subscriber;
9192
case 'bclient':
92-
return new Redis(REDIS_URL);
93+
return new Redis(REDIS_URL, redisOpts);
9394
default:
9495
throw new Error('Unexpected connection type: ', type);
9596
}

lib/queue.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,9 @@ function redisClientGetter(queue, options, initCallback) {
277277
if (connections[type] != null) {
278278
return connections[type];
279279
}
280-
const client = (connections[type] = createClient(type, options.redis));
280+
const clientOptions = _.assign({}, options.redis);
281+
clientOptions.connectionName = this.clientName();
282+
const client = (connections[type] = createClient(type, clientOptions));
281283

282284
// Since connections are lazily initialized, we can't check queue.client
283285
// without initializing a connection. So expose a boolean we can safely

test/test_queue.js

+5
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,11 @@ describe('Queue', () => {
310310
expect(job.id).to.be.ok;
311311
expect(job.data.foo).to.be.eql('bar');
312312
})
313+
.then(
314+
queueFoo.bclient.client('GETNAME').then(name => {
315+
expect(name).to.be.eql(queueFoo.clientName());
316+
})
317+
)
313318
.then(() => {
314319
return queueQux.add({ qux: 'baz' }).then(job => {
315320
expect(job.id).to.be.ok;

0 commit comments

Comments
 (0)