-
Notifications
You must be signed in to change notification settings - Fork 1
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
[BE] redis를 사용해 최근 검색어 저장 #105
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
2ee713d
Merge branch 'back/main' of https://github.com/boostcampwm-2024/web16…
jinddings ea0afd5
Merge branch 'back/main' of https://github.com/boostcampwm-2024/web16…
jinddings 0afe5b1
✨ feat : redis를 이용해 최근 검색 단어 저장(#57):
jinddings a617038
✨ feat: API 분리를 위해 chart 전용으로 변경#54
uuuo3o e23424b
✨ feat: 프론트에서 필요한 값만 반환할 수 있도록 DTO 수정#54
uuuo3o 0203e65
🎨 style: 코드 순서 변경#54
uuuo3o 00677ba
🔥 remove: 불필요한 파일 삭제#54
uuuo3o 383a166
📝 docs: 파일명 변경 및 swagger 문서 수정#54
uuuo3o 463c4cd
➕ add: 차트 그리기에 필요한 값 추가 및 인터페이스 이름 변경#54
uuuo3o 764de7b
🚚 rename: 중복되는 이름 변경#54
uuuo3o 98b8b57
✨ feat: 주식 현재가 API에 사용할 interface, dto 구현#54
uuuo3o 4fe008b
✨ feat: 주식 현재가 API 요청 로직 구현#54
uuuo3o 7dd9da8
♻️ refactor: requestApi 함수 분리 및 불필요한 파일 삭제#55
uuuo3o 6df873c
🚚 rename: 이름을 명확하게 변경#55
uuuo3o 875f2a7
✨ feat: 주식현재가 일자별 API에 사용할 interface, dto 구현#55
uuuo3o e56921a
✨ feat: 주식현재가 일자별 API 요청 로직 구현#55
uuuo3o 7a61c8d
🚑 !HOTFIX : 도커 컨테이너 시간 설정
jinddings 850e53b
🚑 !HOTFIX : docker 시간 설정 명령어 수정
jinddings 5eb4fc5
🚑 !HOTFIX : docker 시간 설정 명령어 수정
jinddings e028917
🔧 fix : auth api 경로 변경(#57)
jinddings d218da8
🚚 rename : redisUtil -> redisDomainService로 클래스 및 파일 이름 변경(#57)
jinddings 3bb0365
✨ feat : 최근 검색어 10 개만 저장하도록 수정(#57)
jinddings 2b2b642
Merge branch 'back/main' into feature/api/stockList-#57
jinddings b19180c
♻️ refactor : lint 오류 수정(#57)
jinddings 6bd2c54
Merge branch 'feature/api/stockList-#57' of https://github.com/boostc…
jinddings File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { Injectable, Inject } from '@nestjs/common'; | ||
import Redis from 'ioredis'; | ||
|
||
@Injectable() | ||
export class RedisDomainService { | ||
constructor( | ||
@Inject('REDIS_CLIENT') | ||
private readonly redis: Redis, | ||
) {} | ||
|
||
async get(key: string): Promise<string | null> { | ||
return this.redis.get(key); | ||
} | ||
|
||
async set(key: string, value: string, expires?: number): Promise<'OK'> { | ||
if (expires) { | ||
return this.redis.set(key, value, 'EX', expires); | ||
} | ||
return this.redis.set(key, value); | ||
} | ||
|
||
async del(key: string): Promise<number> { | ||
return this.redis.del(key); | ||
} | ||
|
||
async zadd(key: string, score: number, member: string): Promise<number> { | ||
return this.redis.zadd(key, score, member); | ||
} | ||
|
||
async zcard(key: string): Promise<number> { | ||
return this.redis.zcard(key); | ||
} | ||
|
||
async zrange(key: string, start: number, stop: number): Promise<string[]> { | ||
return this.redis.zrange(key, start, stop); | ||
} | ||
|
||
async zremrangebyrank( | ||
key: string, | ||
start: number, | ||
stop: number, | ||
): Promise<number> { | ||
return this.redis.zremrangebyrank(key, start, stop); | ||
} | ||
|
||
async zrevrange(key: string, start: number, stop: number): Promise<string[]> { | ||
return this.redis.zrevrange(key, start, stop); | ||
} | ||
|
||
async zrem(key: string, member: string): Promise<number> { | ||
return this.redis.zrem(key, member); | ||
} | ||
|
||
async expire(key: string, seconds: number): Promise<number> { | ||
return this.redis.expire(key, seconds); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// src/common/redis/redis.module.ts | ||
import { Global, Module } from '@nestjs/common'; | ||
import Redis from 'ioredis'; | ||
import { RedisDomainService } from './redis.domain-service'; | ||
|
||
@Global() | ||
@Module({ | ||
providers: [ | ||
{ | ||
provide: 'REDIS_CLIENT', | ||
useFactory: () => { | ||
return new Redis({ | ||
host: process.env.REDIS_HOST, | ||
port: Number(process.env.REDIS_PORT), | ||
}); | ||
}, | ||
}, | ||
RedisDomainService, | ||
], | ||
exports: [RedisDomainService, 'REDIS_CLIENT'], | ||
}) | ||
export class RedisModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Provider } from '@nestjs/common'; | ||
import Redis from 'ioredis'; | ||
import dotenv from 'dotenv'; | ||
|
||
dotenv.config(); | ||
export const RedisProvider: Provider = { | ||
provide: 'REDIS_CLIENT', | ||
useFactory: () => { | ||
return new Redis({ | ||
host: process.env.REDIS_HOST, | ||
port: Number(process.env.REDIS_PORT), | ||
}); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ export interface SearchParams { | |
name?: string; | ||
market?: string; | ||
code?: string; | ||
userId: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
import { RedisDomainService } from 'src/common/redis/redis.domain-service'; | ||
import { RedisModule } from 'src/common/redis/redis.module'; | ||
import { StockListRepository } from './stock-list.repostiory'; | ||
import { StockListService } from './stock-list.service'; | ||
import { StockListController } from './stock-list.controller'; | ||
import { Stocks } from './stock-list.entity'; | ||
|
||
@Module({ | ||
imports: [TypeOrmModule.forFeature([Stocks])], | ||
imports: [TypeOrmModule.forFeature([Stocks]), RedisModule], | ||
controllers: [StockListController], | ||
providers: [StockListRepository, StockListService], | ||
providers: [StockListRepository, StockListService, RedisDomainService], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 이거 RedisModule 임포트하면 providers에 RedisDomainService 추가 안해도 잘 동작하더라고요! providers에서는 빼도 될 것 같습니당 |
||
exports: [], | ||
}) | ||
export class StockListModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟢 바꾸셨네용 좋습니다!! 저도 참고하겠습니다