From 918d8f88be2c92411b36a1c791a4ff0e933d3d21 Mon Sep 17 00:00:00 2001 From: khee2 <21keunghee@gmail.com> Date: Thu, 13 Jun 2024 21:51:02 +0900 Subject: [PATCH] =?UTF-8?q?[feat]=20=EB=A9=94=EC=8B=9C=EC=A7=80=20?= =?UTF-8?q?=EB=A1=9C=EB=93=9C,=20=EC=A0=80=EC=9E=A5=EC=8B=9C=2024=EC=8B=9C?= =?UTF-8?q?=EA=B0=84=EB=A7=88=EB=8B=A4=20redis=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Backend/domain/message/service/MessageService.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/SafeNet/Backend/domain/message/service/MessageService.java b/src/main/java/com/SafeNet/Backend/domain/message/service/MessageService.java index 72d7cd9..013a13a 100644 --- a/src/main/java/com/SafeNet/Backend/domain/message/service/MessageService.java +++ b/src/main/java/com/SafeNet/Backend/domain/message/service/MessageService.java @@ -31,6 +31,7 @@ public MessageService( this.messageRepository = messageRepository; this.messageRoomRepository = messageRoomRepository; } + public void saveMessage(MessageDto messageDto) { MessageRoom messageRoom = messageRoomRepository.findByRoomId(messageDto.getRoomId()) .orElseThrow(() -> new IllegalArgumentException("해당 쪽지방이 존재하지 않습니다.")); @@ -49,7 +50,7 @@ public void saveMessage(MessageDto messageDto) { redisTemplateMessage.setValueSerializer(new Jackson2JsonRedisSerializer<>(MessageDto.class)); redisTemplateMessage.opsForList().rightPush(messageDto.getRoomId(), messageDto); - redisTemplateMessage.expire(messageDto.getRoomId(), 1, TimeUnit.HOURS); // redis에서 1시간마다 삭제 + redisTemplateMessage.expire(messageDto.getRoomId(), 24, TimeUnit.HOURS); // redis에서 24시간마다 삭제 } /** @@ -78,7 +79,8 @@ public List loadMessage(String roomId) { .build(); messageList.add(messageDto); redisTemplateMessage.setValueSerializer(new Jackson2JsonRedisSerializer<>(Message.class)); // 직렬화 - redisTemplateMessage.opsForList().rightPush(roomId, messageDto); // redis 저장 + redisTemplateMessage.opsForList().rightPush(roomId, messageDto); // redis 저장 + redisTemplateMessage.expire(roomId, 24, TimeUnit.HOURS); // redis에서 24시간마다 삭제 } } else { // 4. 뒤쪽에 데이터 붙이기 messageList.addAll(redisMessageList);