Johann150
095802d059
Some checks failed
ci/woodpecker/push/lint-client Pipeline failed
ci/woodpecker/push/lint-backend Pipeline failed
ci/woodpecker/push/lint-sw Pipeline failed
ci/woodpecker/push/lint-foundkey-js Pipeline was successful
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/test Pipeline failed
35 lines
879 B
TypeScript
35 lines
879 B
TypeScript
import Logger from '@/services/logger.js';
|
|
import config from './index.js';
|
|
|
|
const logger = new Logger('config:redis');
|
|
|
|
function getRedisFamily(family?: string | number): number {
|
|
const familyMap = {
|
|
ipv4: 4,
|
|
ipv6: 6,
|
|
dual: 0,
|
|
};
|
|
if (typeof family === 'string' && family in familyMap) {
|
|
return familyMap[family as keyof typeof familyMap];
|
|
} else if (typeof family === 'number' && Object.values(familyMap).includes(family)) {
|
|
return family;
|
|
}
|
|
|
|
if (typeof family !== 'undefined') {
|
|
logger.warn(`redis family "${family}" is invalid, defaulting to "dual"`);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
export function getRedisOptions(keyPrefix?: string): Record<string, string | number | undefined> {
|
|
return {
|
|
port: config.redis.port,
|
|
host: config.redis.host,
|
|
family: getRedisFamily(config.redis.family),
|
|
password: config.redis.pass,
|
|
db: config.redis.db || 0,
|
|
keyPrefix,
|
|
};
|
|
}
|