Skip to content

Commit

Permalink
feat: handle redis uri queries
Browse files Browse the repository at this point in the history
  • Loading branch information
manast authored Feb 21, 2022
1 parent 4150d5f commit 54e5463
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
10 changes: 7 additions & 3 deletions lib/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,10 @@ function redisClientGetter(queue, options, initCallback) {
}

function redisOptsFromUrl(urlString) {
const redisOpts = {};
let redisOpts = {};
try {
const redisUrl = url.parse(urlString);
redisOpts.port = redisUrl.port || 6379;
const redisUrl = url.parse(urlString, true, true);
redisOpts.port = parseInt(redisUrl.port || '6379', 10);
redisOpts.host = redisUrl.hostname;
redisOpts.db = redisUrl.pathname ? redisUrl.pathname.split('/')[1] : 0;
if (redisUrl.auth) {
Expand All @@ -320,6 +320,10 @@ function redisOptsFromUrl(urlString) {
redisOpts.username = redisUrl.auth.slice(0, columnIndex);
}
}

if (redisUrl.query) {
redisOpts = { ...redisOpts, ...redisUrl.query };
}
} catch (e) {
throw new Error(e.message);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"cron-parser": "^4.2.1",
"debuglog": "^1.0.0",
"get-port": "^5.1.1",
"ioredis": "^4.27.0",
"ioredis": "^4.28.5",
"lodash": "^4.17.21",
"msgpackr": "^1.5.2",
"p-timeout": "^3.2.0",
Expand Down
12 changes: 12 additions & 0 deletions test/test_connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,16 @@ describe('connection', () => {

await queue.close();
});

it('should accept ioredis options on the query string', async () => {
queue = new Queue(
'connection query string',
'redis://localhost?tls=RedisCloudFixed'
);

expect(queue.clients[0].options).to.have.property('tls');
expect(queue.clients[0].options.tls).to.have.property('ca');

await queue.close();
});
});
14 changes: 10 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3183,16 +3183,17 @@ into-stream@^6.0.0:
from2 "^2.3.0"
p-is-promise "^3.0.0"

ioredis@^4.27.0:
version "4.27.5"
resolved "https://registry.yarnpkg.com/ioredis/-/ioredis-4.27.5.tgz#b62192bb6198f8a5a02947902117150aef39b7f1"
integrity sha512-JJ3HzOzU6kgUk3gKhpx8kxEYn9ruI5TkpOtGvbw/hLyWxfC19T9uCZTgmw4Mci4al4aOCCMfAjYzJ7aqQkLbJg==
ioredis@^4.28.5:
version "4.28.5"
resolved "https://registry.yarnpkg.com/ioredis/-/ioredis-4.28.5.tgz#5c149e6a8d76a7f8fa8a504ffc85b7d5b6797f9f"
integrity sha512-3GYo0GJtLqgNXj4YhrisLaNNvWSNwSS2wS4OELGfGxH8I69+XfNdnmV1AyN+ZqMh0i7eX+SWjrwFKDBDgfBC1A==
dependencies:
cluster-key-slot "^1.1.0"
debug "^4.3.1"
denque "^1.1.0"
lodash.defaults "^4.2.0"
lodash.flatten "^4.4.0"
lodash.isarguments "^3.1.0"
p-map "^2.1.0"
redis-commands "1.7.0"
redis-errors "^1.2.0"
Expand Down Expand Up @@ -4021,6 +4022,11 @@ lodash.flattendeep@^4.4.0:
resolved "https://registry.yarnpkg.com/lodash.flattendeep/-/lodash.flattendeep-4.4.0.tgz#fb030917f86a3134e5bc9bec0d69e0013ddfedb2"
integrity sha1-+wMJF/hqMTTlvJvsDWngAT3f7bI=

lodash.isarguments@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/lodash.isarguments/-/lodash.isarguments-3.1.0.tgz#2f573d85c6a24289ff00663b491c1d338ff3458a"
integrity sha1-L1c9hcaiQon/AGY7SRwdM4/zRYo=

lodash.ismatch@^4.4.0:
version "4.4.0"
resolved "https://registry.yarnpkg.com/lodash.ismatch/-/lodash.ismatch-4.4.0.tgz#756cb5150ca3ba6f11085a78849645f188f85f37"
Expand Down

0 comments on commit 54e5463

Please sign in to comment.