Queue is missing redis username support from url
Created by: StefanCenusa
Description
Queue doesn't parse the username out of the redis url. Of course, username could be passed with redis options, but I think it would be nice to parse/get all the information from the url string if possible.
function redisOptsFromUrl(urlString) {
const redisOpts = {};
try {
const redisUrl = url.parse(urlString);
redisOpts.port = redisUrl.port || 6379;
redisOpts.host = redisUrl.hostname;
redisOpts.db = redisUrl.pathname ? redisUrl.pathname.split('/')[1] : 0;
if (redisUrl.auth) {
redisOpts.password = redisUrl.auth.split(':')[1];
}
} catch (e) {
throw new Error(e.message);
}
return redisOpts;
}
https://github.com/OptimalBits/bull/blob/develop/lib/queue.js#L305
A simple solution would be:
if (redisUrl.auth) {
const columnIndex = redisUrl.auth.indexOf(':');
redisOpts.password = redisUrl.auth.slice(columnIndex + 1);
if (columnIndex > 0) {
redisOpts.user = redisUrl.auth.slice(0, columnIndex);
}
}
Should I open a PR for this change?
Bull version
3.27.0