temp
This commit is contained in:
@@ -1,9 +1,15 @@
|
||||
import { Redis } from 'ioredis';
|
||||
import { useConfig } from '@kevisual/use-config';
|
||||
import { useConfig } from '@kevisual/use-config/env';
|
||||
import { useContextKey } from '@kevisual/use-config/context';
|
||||
const config = useConfig<{
|
||||
redis: ConstructorParameters<typeof Redis>;
|
||||
}>();
|
||||
const configEnv = useConfig();
|
||||
|
||||
const redisConfig = {
|
||||
host: configEnv.REDIS_HOST || 'localhost',
|
||||
port: configEnv.REDIS_PORT ? parseInt(configEnv.REDIS_PORT) : 6379,
|
||||
password: configEnv.REDIS_PASSWORD || undefined,
|
||||
db: configEnv.REDIS_DB ? parseInt(configEnv.REDIS_DB) : 0,
|
||||
};
|
||||
|
||||
// 配置 Redis 连接
|
||||
export const redis = new Redis({
|
||||
host: 'localhost', // Redis 服务器的主机名或 IP 地址
|
||||
@@ -16,7 +22,6 @@ export const redis = new Redis({
|
||||
return Math.min(times * 50, 2000); // 每次重试时延迟增加
|
||||
},
|
||||
maxRetriesPerRequest: null, // 允许请求重试的次数 (如果需要无限次重试)
|
||||
...config.redis,
|
||||
});
|
||||
useContextKey('redis', () => redis);
|
||||
// 监听连接事件
|
||||
|
||||
@@ -1,19 +1,16 @@
|
||||
import { useConfig } from '@kevisual/use-config';
|
||||
import { useConfig } from '@kevisual/use-config/env';
|
||||
import { Sequelize } from 'sequelize';
|
||||
import { useContextKey, useContext } from '@kevisual/use-config/context';
|
||||
import { useContextKey } from '@kevisual/use-config/context';
|
||||
|
||||
type PostgresConfig = {
|
||||
postgres: {
|
||||
username: string;
|
||||
password: string;
|
||||
host: string;
|
||||
port: number;
|
||||
database: string;
|
||||
};
|
||||
const configEnv = useConfig();
|
||||
|
||||
const postgresConfig = {
|
||||
username: configEnv.POSTGRES_USERNAME,
|
||||
password: configEnv.POSTGRES_PASSWORD,
|
||||
host: configEnv.POSTGRES_HOST,
|
||||
port: configEnv.POSTGRES_PORT ? parseInt(configEnv.POSTGRES_PORT) : 5432,
|
||||
database: configEnv.POSTGRES_DATABASE,
|
||||
};
|
||||
const config = useConfig<PostgresConfig>();
|
||||
|
||||
const postgresConfig = config.postgres;
|
||||
|
||||
if (!postgresConfig) {
|
||||
console.error('postgres config is required');
|
||||
|
||||
Reference in New Issue
Block a user