Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4-1 [BE] [메인 - 인기 검색어] redis를 이용하여 상위 10개의 인기 검색어 rank를 관리하는 시스템을 만든다. #6

Merged
merged 8 commits into from
Nov 15, 2022

Conversation

JunYupK
Copy link
Collaborator

@JunYupK JunYupK commented Nov 14, 2022

개요

http://localhost:4000/popular
http://localhost:4000/popular/{search}
4000번 포트의 인기 검색어의 데이터를 받아 올 수 있는 api 개발

작업사항

  • get popular 를 호출 할 시 1~10위 까지의 검색어와 검색한 수를 받을 수 있는 api를 만들었습니다.
  • 검색어의 score를 업데이트 하는 부분은 우선 내부 search api가 개발 되면 해당 api에서 update하는 식으로 구현이 이루어질 것이나, 우선 테스트를 위해 popular/{word} api 요청 시에 해당하는 검색어를 redis 에서 찾아보고 존재하면 score를 증가하는 기능이 우선 추가 되었습니다.
  • 이후 BE api 요청 시에 validation 검사를 위한 pipe를 추가할 예정이나, 추가 적인 dto가 설계 되면 추가할 예정입니다.

리뷰 요청사항

  • api get 요청시에 일어날 수 있는 예외 처리
  • popular/popular.service.ts 부분의 10위 까지의 검색어를 가져오는 함수인 getAll() 에서의 효율성 개선과 좀 더 클린코드로 바꿀만한 요소

popular api 기본 뼈대 설정 및 캐싱
popular api에 Redis 연결 및 get :string 요청으로 검색어 입력시에 score를 계산하고, get 요청시에 1~10위 까지의 검색 수와 키워드를
return하는 기능 추가
@JunYupK JunYupK changed the title Feature/ranking system [BE] [Popular] 인기검색어 api 개발 Nov 14, 2022
@JunYupK JunYupK changed the title [BE] [Popular] 인기검색어 api 개발 4-1 [BE] [메인 - 인기 검색어] redis를 이용하여 상위 10개의 인기 검색어 rank를 관리하는 시스템을 만든다. Nov 14, 2022
import { InjectRedis } from '@liaoliaots/nestjs-redis';
import Redis from 'ioredis';
@Injectable()
export class PopularService {
Copy link

@sujinleeme sujinleeme Nov 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 테스트 코드를 만들어보실 수 있나요?

  2. 설명에 API 요청시 필요한 파라미터와 타입을 정해주시겠어요?

  3. 잘못된 요청이 있을 시 어떤 에러가 발생되나요? 이를 테스트 케이스에 넣으실 수 있나요?

@@ -3,6 +3,6 @@ import { AppModule } from './app.module';

async function bootstrap() {
const app = await NestFactory.create(AppModule);
await app.listen(3001);
await app.listen(4000);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

포트 번호를 환경변수로 관리할 수 있나요?

private populars: Popular[] = [];
async getAll() {
this.populars = [];
const topTen = await this.redis.zrevrangebyscore('Top10', '+inf', 1);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Top10 key를 상수로 관리할 수 있을까요?

Copy link
Member

@leesungbin leesungbin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

갓준엽

.czrc Outdated
@@ -0,0 +1 @@
{ "path": "cz-conventional-changelog" }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 파일은 제가 .gitignore에 추가해놨으니 날려주시면 됩니당

"cache-manager": "^5.1.3",
"cache-manager-redis-store": "^3.0.1",
"ioredis": "^5.2.4",
"redis": "^4.5.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분은 필요한 패키지만 정리해주실 예정

Comment on lines 7 to 16
imports: [
RedisModule.forRoot({
config: {
host: 'localhost',
port: 3003,
},
}),
],
controllers: [PopularController],
providers: [PopularService],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

popular controller에 module이 생기고 redisModule import 할 예정
여기서는 popularModule import 할 예정

@JunYupK JunYupK merged commit 3ce899e into dev Nov 15, 2022
@JunYupK JunYupK deleted the feature/ranking-system branch November 16, 2022 06:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants