Further updates to typing.

This commit is contained in:
mike12345567 2023-11-03 18:03:11 +00:00
parent 001cf01303
commit 7bf307b0c2
2 changed files with 13 additions and 9 deletions

View File

@ -59,7 +59,7 @@ export enum SelectableDatabase {
UNUSED_14 = 15, UNUSED_14 = 15,
} }
export function getRedisOptions() { export function getRedisConnectionDetails() {
let password = env.REDIS_PASSWORD let password = env.REDIS_PASSWORD
let url: string[] | string = env.REDIS_URL.split("//") let url: string[] | string = env.REDIS_URL.split("//")
// get rid of the protocol // get rid of the protocol
@ -75,9 +75,18 @@ export function getRedisOptions() {
} }
const [host, port] = url.split(":") const [host, port] = url.split(":")
return {
host,
password,
port: parseInt(port),
}
}
export function getRedisOptions() {
const { host, password, port } = getRedisConnectionDetails()
let redisOpts: Redis.RedisOptions = { let redisOpts: Redis.RedisOptions = {
connectTimeout: CONNECT_TIMEOUT_MS, connectTimeout: CONNECT_TIMEOUT_MS,
port: parseInt(port), port: port,
host, host,
password, password,
} }
@ -93,12 +102,7 @@ export function getRedisOptions() {
dnsLookup: (address: string, callback: any) => callback(null, address), dnsLookup: (address: string, callback: any) => callback(null, address),
} as Redis.ClusterOptions } as Redis.ClusterOptions
} }
return { return opts
opts,
host,
password,
port: parseInt(port),
}
} }
export function addDbPrefix(db: string, key: string) { export function addDbPrefix(db: string, key: string) {

View File

@ -39,7 +39,7 @@ function getApiLimitPerSecond(): number {
let rateLimitStore: any = null let rateLimitStore: any = null
if (!env.isTest()) { if (!env.isTest()) {
const { password, host, port } = redis.utils.getRedisOptions() const { password, host, port } = redis.utils.getRedisConnectionDetails()
let options: KoaRateLimitOptions = { let options: KoaRateLimitOptions = {
socket: { socket: {
host: host, host: host,