johnycash
Version:
Easy distributed caching for Node.js
22 lines • 829 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseRedisConnectionString = parseRedisConnectionString;
function parseRedisConnectionString(redisUrl) {
let url;
try {
url = new URL(redisUrl);
}
catch (err) {
throw new Error(`Invalid Redis URL`);
}
const host = url.hostname;
const port = Number(url.port) || 6379;
const username = url.username || undefined;
const password = url.password || undefined;
const db = url.pathname ? parseInt(url.pathname.slice(1), 10) : 0;
const family = url.searchParams.get('family');
const isTls = url.protocol === 'rediss:';
const tls = isTls ? true : false;
return { host, port, username, password, db, tls, ...(family && { family }) };
}
//# sourceMappingURL=redis-conig-parser.js.map