feat: 集成Redis模块并重构限流存储机制
This commit is contained in:
@@ -8,6 +8,7 @@ import { ConfigModule } from '@nestjs/config';
|
||||
import { ScheduleModule } from '@nestjs/schedule';
|
||||
import { ThrottlerModule, ThrottlerGuard } from '@nestjs/throttler';
|
||||
import { LoggerModule } from './common/logger/logger.module';
|
||||
import { RedisModule, ThrottlerStorageRedisService } from './redis';
|
||||
import { CheckinsModule } from './checkins/checkins.module';
|
||||
import { AiCoachModule } from './ai-coach/ai-coach.module';
|
||||
import { TrainingPlansModule } from './training-plans/training-plans.module';
|
||||
@@ -33,10 +34,18 @@ import { HealthProfilesModule } from './health-profiles/health-profiles.module';
|
||||
envFilePath: '.env',
|
||||
}),
|
||||
ScheduleModule.forRoot(),
|
||||
ThrottlerModule.forRoot([{
|
||||
ttl: 60000, // 时间窗口:60秒
|
||||
limit: 100, // 每个时间窗口最多100个请求
|
||||
}]),
|
||||
// 限流模块必须在 RedisModule 之后导入,以确保 Redis 连接可用
|
||||
RedisModule,
|
||||
ThrottlerModule.forRootAsync({
|
||||
useFactory: (throttlerStorage: ThrottlerStorageRedisService) => ({
|
||||
throttlers: [{
|
||||
ttl: 60000, // 时间窗口:60秒
|
||||
limit: 100, // 每个时间窗口最多100个请求
|
||||
}],
|
||||
storage: throttlerStorage,
|
||||
}),
|
||||
inject: [ThrottlerStorageRedisService],
|
||||
}),
|
||||
LoggerModule,
|
||||
DatabaseModule,
|
||||
UsersModule,
|
||||
|
||||
Reference in New Issue
Block a user