Skip to content

Commit

Permalink
Merge pull request #154 from boostcampwm-2024/be-feat#122
Browse files Browse the repository at this point in the history
[BE] 작은 리팩토링, Redis 캐싱 도입
  • Loading branch information
EnvyW6567 authored Nov 25, 2024
2 parents 37bd4cb + d85444a commit 40bccb3
Show file tree
Hide file tree
Showing 24 changed files with 300 additions and 50 deletions.
10 changes: 10 additions & 0 deletions backend/console-server/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
version: '3.8'
services:

redis:
image: redis:latest
container_name: app-redis
restart: always
ports:
- "6379:6379"
networks:
- app-network

nginx:
image: nginx:latest
ports:
Expand Down
177 changes: 177 additions & 0 deletions backend/console-server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions backend/console-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@
"dependencies": {
"@clickhouse/client": "^1.8.0",
"@nestjs-modules/mailer": "^2.0.2",
"@nestjs/cache-manager": "^2.3.0",
"@nestjs/common": "^10.0.0",
"@nestjs/config": "^3.3.0",
"@nestjs/core": "^10.0.0",
"@nestjs/mapped-types": "^2.0.6",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/swagger": "^8.0.5",
"@nestjs/typeorm": "^10.0.2",
"cache-manager": "^5.7.6",
"cache-manager-redis-yet": "^5.1.5",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1",
"handlebars": "^4.7.8",
Expand Down
10 changes: 8 additions & 2 deletions backend/console-server/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,21 @@ import mailerConfig from './config/mailer.config';
import { ClickhouseModule } from './clickhouse/clickhouse.module';
import { LogModule } from './log/log.module';
import clickhouseConfig from './config/clickhouse.config';
import { CacheModule } from '@nestjs/cache-manager';
import redisConfig from './config/redis.config';

@Module({
imports: [
ConfigModule.forRoot({ isGlobal: true, load: [mailerConfig, clickhouseConfig] }),
TypeOrmModule.forRootAsync(typeOrmConfig.asProvider()),
ProjectModule,
ClickhouseModule,
LogModule,
CacheModule.registerAsync({
isGlobal: true,
...redisConfig.asProvider(),
}),
MailModule,
ProjectModule,
LogModule,
],
controllers: [AppController],
providers: [AppService],
Expand Down
6 changes: 3 additions & 3 deletions backend/console-server/src/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Injectable } from '@nestjs/common';

@Injectable()
export class AppService {
getHello(): string {
return 'Hello World!';
}
getHello(): string {
return 'Hello World!';
}
}
16 changes: 16 additions & 0 deletions backend/console-server/src/config/redis.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { registerAs } from '@nestjs/config';
import { redisStore } from 'cache-manager-redis-yet';

export default registerAs('redisConfig', async () => {
const store = await redisStore({
socket: {
host: process.env.REDIS_HOST || 'localhost',
port: Number(process.env.REDIS_PORT) || 6379,
},
ttl: 60 * 1000,
});

return {
store: store,
};
});
Original file line number Diff line number Diff line change
@@ -1,28 +1,40 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AnalyticService } from './analytic.service';
import { AnalyticController } from './analytic.controller';
import type { TestingModule } from '@nestjs/testing';
import { Test } from '@nestjs/testing';
import { AnalyticsService } from './analytics.service';
import { AnalyticsController } from './analytics.controller';
import { CACHE_MANAGER } from '@nestjs/cache-manager';

describe('AnalyticController 테스트', () => {
let controller: AnalyticController;
let service: AnalyticService;
describe('AnalyticsController 테스트', () => {
let controller: AnalyticsController;
let service: AnalyticsService;

const mockLogService = {
getProjectDAU: jest.fn(),
};

const mockCacheManager = {
get: jest.fn(),
set: jest.fn(),
del: jest.fn(),
};

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [AnalyticController],
controllers: [AnalyticsController],
providers: [
{
provide: AnalyticService,
provide: AnalyticsService,
useValue: mockLogService,
},
{
provide: CACHE_MANAGER,
useValue: mockCacheManager,
},
],
}).compile();

controller = module.get<AnalyticController>(AnalyticController);
service = module.get<AnalyticService>(AnalyticService);
controller = module.get<AnalyticsController>(AnalyticsController);
service = module.get<AnalyticsService>(AnalyticsService);

jest.clearAllMocks();
});
Expand Down
Loading

0 comments on commit 40bccb3

Please sign in to comment.