fix: properly support redis db (#517)

This commit is contained in:
Philip Okugbe
2024-11-28 18:54:28 +00:00
committed by GitHub
parent ca186f3c0e
commit f178e6654f
3 changed files with 14 additions and 2 deletions

View File

@ -18,15 +18,25 @@ export async function comparePasswordHash(
export type RedisConfig = {
host: string;
port: number;
db: number;
password?: string;
};
export function parseRedisUrl(redisUrl: string): RedisConfig {
// format - redis[s]://[[username][:password]@][host][:port][/db-number]
const { hostname, port, password } = new URL(redisUrl);
const { hostname, port, password, pathname } = new URL(redisUrl);
const portInt = parseInt(port, 10);
return { host: hostname, port: portInt, password };
let db: number = 0;
// extract db value if present
if (pathname.length > 1) {
const value = pathname.slice(1);
if (!isNaN(parseInt(value))){
db = parseInt(value, 10);
}
}
return { host: hostname, port: portInt, password, db };
}
export function createRetryStrategy() {