new redis url parser

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-02-11 22:31:22 +01:00
parent 497b05eb32
commit 85e4922dc3

View File

@@ -1,9 +1,12 @@
const parse = (connectionString: string) => {
const url = new URL(connectionString);
const match = connectionString.match(/redis:\/\/(.+?):(.+?)@(.+?):(.+)/);
if (!match) {
throw new Error('Invalid connection string');
}
return {
host: url.hostname,
port: Number(url.port),
password: url.password,
host: match[3]!,
port: Number(match[4]),
password: match[2]!,
} as const;
};