-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: dev db connection 개수 조정 (#268)
* feat: 최근 접속 시간 조회 기능 구현 * chore: GetMemberActivityResponse에서 변수명 수정 * chore: dev connection pool 설정 변경
- Loading branch information
Showing
15 changed files
with
394 additions
and
15 deletions.
There are no files selected for viewing
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
7 changes: 7 additions & 0 deletions
7
layer-admin/src/main/java/org/layer/common/exception/AdminException.java
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,7 @@ | ||
package org.layer.common.exception; | ||
|
||
public class AdminException extends BaseCustomException { | ||
public AdminException(ExceptionType exceptionType) { | ||
super(exceptionType); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
layer-admin/src/main/java/org/layer/config/RedisConfigDev.java
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,56 @@ | ||
package org.layer.config; | ||
|
||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.data.redis.connection.RedisConnectionFactory; | ||
import org.springframework.data.redis.connection.RedisStandaloneConfiguration; | ||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; | ||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories; | ||
import org.springframework.data.redis.serializer.StringRedisSerializer; | ||
|
||
@Profile({"dev", "local"}) | ||
@Configuration | ||
@EnableRedisRepositories | ||
public class RedisConfigDev { | ||
@Value("${spring.data.redis.host}") | ||
private String host; | ||
|
||
@Value("${spring.data.redis.port}") | ||
private int port; | ||
|
||
@Value("${spring.data.redis.password}") | ||
private String password; | ||
|
||
|
||
|
||
// dev에서 최근 서비스 이용 시점 기록 - 2번 데이터베이스 | ||
@Bean | ||
public RedisConnectionFactory redisConnectionFactory() { | ||
RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration(); | ||
redisStandaloneConfiguration.setHostName(host); | ||
redisStandaloneConfiguration.setPort(port); | ||
redisStandaloneConfiguration.setDatabase(2); // 2번 데이터베이스 | ||
|
||
return new LettuceConnectionFactory(redisStandaloneConfiguration); | ||
|
||
} | ||
|
||
@Bean | ||
@Qualifier("recentAccessHistory") | ||
RedisTemplate<String, String> redisTemplate() { | ||
RedisTemplate<String, String> redisTemplate = new RedisTemplate<>(); | ||
redisTemplate.setConnectionFactory(redisConnectionFactory()); | ||
|
||
// String - String | ||
redisTemplate.setKeySerializer(new StringRedisSerializer()); | ||
redisTemplate.setValueSerializer(new StringRedisSerializer()); | ||
redisTemplate.setConnectionFactory(redisConnectionFactory()); | ||
|
||
return redisTemplate; | ||
} | ||
|
||
} |
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
6 changes: 3 additions & 3 deletions
6
layer-admin/src/main/java/org/layer/member/controller/dto/GetMemberActivityResponse.java
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,34 @@ | ||
server: | ||
port: 3000 | ||
|
||
spring: | ||
config: | ||
import: application-secret.properties | ||
datasource: | ||
driver-class-name: org.h2.Driver | ||
url: jdbc:h2:mem:layer-local-db;DATABASE_TO_UPPER=FALSE;mode=mysql # H2 접속 정보 (전부 소문자로 지정) | ||
username: sa | ||
password: | ||
h2: | ||
console: | ||
enabled: true | ||
path: /h2-console | ||
jpa: | ||
database-platform: org.hibernate.dialect.H2Dialect | ||
hibernate: | ||
ddl-auto: create | ||
properties: | ||
hibernate: | ||
format_sql: true | ||
show_sql: true | ||
open-in-view: false | ||
defer-datasource-initialization: true | ||
|
||
data: | ||
redis: | ||
host: localhost | ||
port: 6379 | ||
password: | ||
|
||
admin: | ||
password: ${ADMIN_PASSWORD} |
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
51 changes: 51 additions & 0 deletions
51
layer-api/src/main/java/org/layer/aop/RecentAccessHistoryAop.java
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,51 @@ | ||
package org.layer.aop; | ||
|
||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.log4j.Log4j2; | ||
import org.aspectj.lang.ProceedingJoinPoint; | ||
import org.aspectj.lang.annotation.Around; | ||
import org.aspectj.lang.annotation.Aspect; | ||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.time.Duration; | ||
import java.time.LocalDateTime; | ||
|
||
@RequiredArgsConstructor | ||
@Aspect | ||
@Component | ||
@Log4j2 | ||
public class RecentAccessHistoryAop { | ||
private final RedisTemplate<String, String> redisTemplate; | ||
|
||
// 모든 layer-api 모듈 내의 controller package에 존재하는 클래스 | ||
@Around("execution(* org.layer.domain..controller..*(..))") | ||
public Object recordRecentAccessHistory(ProceedingJoinPoint pjp) throws Throwable { | ||
Long memberId = getCurrentMemberId(); | ||
|
||
if(memberId != null) { // 멤버 아이디가 있다면 현재 시간을 저장. | ||
setRecentTime(Long.toString(memberId), LocalDateTime.now().toString()); | ||
} | ||
Object result = pjp.proceed(); | ||
return result; | ||
} | ||
|
||
private Long getCurrentMemberId() { | ||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); | ||
|
||
try { | ||
return Long.parseLong(authentication.getName()); | ||
} catch(Exception e) { | ||
return null; | ||
} | ||
} | ||
|
||
|
||
private void setRecentTime(String memberId, String recentTime) { | ||
Duration ttl = Duration.ofDays(30 * 6); // 6개월 | ||
redisTemplate.opsForValue().set(memberId, recentTime, ttl); | ||
} | ||
} |
Oops, something went wrong.