perf router template

This commit is contained in:
2025-04-07 14:36:52 +08:00
parent 117be3062d
commit 6807388ab5
18 changed files with 996 additions and 464 deletions

View File

@@ -1,9 +0,0 @@
import { Mark, markModelInit } from '@kevisual/mark';
export { Mark, markModelInit };
export const init = () => {
markModelInit({
tableName: '',
});
};

28
src/modules/redis.ts Normal file
View File

@@ -0,0 +1,28 @@
import { Redis } from 'ioredis';
// 配置 Redis 连接
export const redis = new Redis({
host: 'localhost', // Redis 服务器的主机名或 IP 地址
port: 6379, // Redis 服务器的端口号
// password: 'your_password', // Redis 的密码 (如果有)
db: 0, // 要使用的 Redis 数据库索引 (0-15)
keyPrefix: '', // key 前缀
retryStrategy(times) {
// 连接重试策略
return Math.min(times * 50, 2000); // 每次重试时延迟增加
},
maxRetriesPerRequest: null, // 允许请求重试的次数 (如果需要无限次重试)
});
// 监听连接事件
redis.on('connect', () => {
console.log('Redis 连接成功');
});
redis.on('error', (err) => {
console.error('Redis 连接错误', err);
});
// 初始化 Redis 客户端
export const redisPublisher = new Redis(); // 用于发布消息
export const redisSubscriber = new Redis(); // 用于订阅消息

View File

@@ -1 +1,31 @@
export { sequelize, redis } from '@kevisual/code-center-module';
import { Sequelize } from 'sequelize';
import { useConfig } from '@kevisual/use-config/env';
const config = useConfig();
export type PostgresConfig = {
postgres: {
username: string;
password: string;
host: string;
port: number;
database: string;
};
};
if (!config.POSTGRES_PASSWORD || !config.POSTGRES_USER) {
console.error('postgres config is required password and user');
process.exit(1);
}
const postgresConfig = {
username: config.POSTGRES_USER,
password: config.POSTGRES_PASSWORD,
host: config.POSTGRES_HOST || 'localhost',
port: parseInt(config.POSTGRES_PORT || '5432'),
database: config.POSTGRES_DB || 'postgres',
};
// connect to db
export const sequelize = new Sequelize({
dialect: 'postgres',
...postgresConfig,
// logging: false,
});