diff --git a/lib/utils/index.ts b/lib/utils/index.ts index 150f000d..9cd6da3e 100644 --- a/lib/utils/index.ts +++ b/lib/utils/index.ts @@ -236,6 +236,12 @@ export function parseURL(url: string): Record { if (parsed.port) { result.port = parsed.port; } + if (typeof options.family === "string") { + const intFamily = Number.parseInt(options.family, 10); + if (!Number.isNaN(intFamily)) { + result.family = intFamily; + } + } defaults(result, options); return result; diff --git a/test/unit/redis.ts b/test/unit/redis.ts index f12d2dd9..5ede16bd 100644 --- a/test/unit/redis.ts +++ b/test/unit/redis.ts @@ -96,6 +96,9 @@ describe("Redis", () => { tls: { hostname: "example.test" }, }); expect(option.tls).to.deep.equal({ hostname: "example.test" }); + + option = getOption("redis://localhost?family=6"); + expect(option).to.have.property("family", 6); } catch (err) { stub.restore(); throw err; diff --git a/test/unit/utils.ts b/test/unit/utils.ts index f9386ac9..7aa80822 100644 --- a/test/unit/utils.ts +++ b/test/unit/utils.ts @@ -195,6 +195,14 @@ describe("utils", () => { password: "pass", key: "value", }); + expect(utils.parseURL("redis://127.0.0.1/?family=6")).to.eql({ + host: "127.0.0.1", + family: 6, + }); + expect(utils.parseURL("redis://127.0.0.1/?family=IPv6")).to.eql({ + host: "127.0.0.1", + family: "IPv6", + }); }); });