Files
whale-town-end/src/core/redis/redis.module.ts
moyin bb796a2469 refactor:项目架构重构和命名规范化
- 统一文件命名为snake_case格式(kebab-case  snake_case)
- 重构zulip模块为zulip_core,明确Core层职责
- 重构user-mgmt模块为user_mgmt,统一命名规范
- 调整模块依赖关系,优化架构分层
- 删除过时的文件和目录结构
- 更新相关文档和配置文件

本次重构涉及大量文件重命名和模块重组,
旨在建立更清晰的项目架构和统一的命名规范。
2026-01-08 00:14:14 +08:00

68 lines
2.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* Redis模块配置
*
* 功能描述:
* - 根据环境变量自动选择Redis实现方式
* - 开发环境使用文件存储模拟Redis功能
* - 生产环境连接真实Redis服务器
* - 提供统一的Redis服务注入接口
*
* 职责分离:
* - 服务工厂根据配置创建合适的Redis服务实例
* - 依赖注入为其他模块提供REDIS_SERVICE令牌
* - 环境适配自动适配不同环境的Redis需求
*
* 最近修改:
* - 2025-01-07: 代码规范优化 - 更新导入路径,修正文件重命名后的引用关系
* - 2025-01-07: 代码规范优化 - 完善文件头注释和类注释,添加详细功能说明
*
* @author moyin
* @version 1.0.2
* @since 2025-01-07
* @lastModified 2025-01-07
*/
import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { FileRedisService } from './file_redis.service';
import { RealRedisService } from './real_redis.service';
import { IRedisService } from './redis.interface';
/**
* Redis模块
*
* 职责:
* - 根据环境变量自动选择文件存储或真实Redis服务
* - 提供统一的Redis服务注入接口
* - 管理Redis服务的生命周期
*
* 主要方法:
* - useFactory() - 根据配置创建Redis服务实例
*
* 使用场景:
* - 在需要Redis功能的模块中导入此模块
* - 通过@Inject('REDIS_SERVICE')注入Redis服务
*/
@Module({
imports: [ConfigModule],
providers: [
{
provide: 'REDIS_SERVICE',
useFactory: (configService: ConfigService): IRedisService => {
const useFileRedis = configService.get<string>('USE_FILE_REDIS', 'true') === 'true';
const nodeEnv = configService.get<string>('NODE_ENV', 'development');
// 在开发环境或明确配置使用文件Redis时使用文件存储
if (nodeEnv === 'development' || useFileRedis) {
return new FileRedisService();
} else {
return new RealRedisService(configService);
}
},
inject: [ConfigService],
},
FileRedisService,
RealRedisService,
],
exports: ['REDIS_SERVICE'],
})
export class RedisModule {}