Skip to content

Commit

Permalink
Merge pull request #375 from boostcampwm2023/BE-redisServer-#356
Browse files Browse the repository at this point in the history
[BE/#356] 서버 Redis 연결
  • Loading branch information
koomin1227 authored Dec 7, 2023
2 parents 9be16b8 + 22505e7 commit dfa89bf
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 4 deletions.
71 changes: 71 additions & 0 deletions BE/package-lock.json

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

1 change: 1 addition & 0 deletions BE/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
"firebase-admin": "^11.11.1",
"ioredis": "^5.3.2",
"jsonwebtoken": "^9.0.2",
"jwks-rsa": "^3.1.0",
"multer-s3": "^3.0.1",
Expand Down
2 changes: 2 additions & 0 deletions BE/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { PostsBlockModule } from './posts-block/posts-block.module';
import { UsersBlockModule } from './users-block/users-block.module';
import { LoginModule } from './login/login.module';
import { ChatModule } from './chat/chat.module';
import { RedisService } from './utils/redis';

@Module({
imports: [
Expand Down Expand Up @@ -42,6 +43,7 @@ import { ChatModule } from './chat/chat.module';
provide: APP_PIPE,
useClass: ValidationPipe,
},
//RedisService,
],
})
export class AppModule {}
17 changes: 13 additions & 4 deletions BE/src/chat/chat.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export class ChatService {
}

async findRoomList(userId: string) {
let now = new Set();
const rooms = await this.chatRoomRepository
.createQueryBuilder('chat_room')
.select([
Expand All @@ -85,9 +86,8 @@ export class ChatService {
.orWhere('chat_room.writer = :userId', {
userId: userId,
})
.innerJoin('chat', 'chat', 'chat_room.id = chat.chat_room')
.leftJoin('chat', 'chat', 'chat_room.id = chat.chat_room')
.orderBy('chat.id', 'DESC')
.limit(1)
.addSelect(['user.w.user_hash', 'user.w.profile_img', 'user.w.nickname'])
.leftJoin('user', 'user.w', 'user.w.user_hash = chat_room.writer')
.addSelect(['user.u.user_hash', 'user.u.profile_img', 'user.u.nickname'])
Expand All @@ -96,7 +96,7 @@ export class ChatService {
.leftJoin('post', 'post', 'post.id = chat_room.post_id')
.getRawMany();

return rooms
const result = rooms
.reduce((acc, cur) => {
acc.push({
room_id: cur.chat_room_id,
Expand All @@ -116,7 +116,16 @@ export class ChatService {
}, [])
.sort((a, b) => {
return b.last_chat_date - a.last_chat_date;
});
})
.reduce((acc, cur) => {
if (!now.has(cur.room_id)) {
acc.push(cur);
now.add(cur.room_id);
}
return acc;
}, []);

return result;
}

async findRoomById(roomId: number, userId: string) {
Expand Down
14 changes: 14 additions & 0 deletions BE/src/utils/redis.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Injectable } from '@nestjs/common';
import { Redis } from 'ioredis';

@Injectable()
export class RedisService {
private client: Redis;
constructor() {
this.client = new Redis(6379, '101.101.211.125');
}

async get(key: string) {
return await this.client.get('redis');
}
}

0 comments on commit dfa89bf

Please sign in to comment.