본문 바로가기
728x90
반응형

Spring31

[Spring] redis keys 대신 scan keys 명령어는 한 번에 모든 키를 스캔해서 조회하는 반면, scan 명령어는 한 번에 약 10개씩 정도를 조회합니다. keys는 키 수가 많을 경우 처리시간이 그만큼 많이 소요되며, 그 동안 다른 명령을 처리하지 못합니다. 그래서 대안으로 나온 것이 sacn입니다. scan은 count 값을 정하여 그 count값만큼 여러 번 레디스의 모든 키를 읽어오기 때문에 count의 개수를 낮게 잡으면 count만큼 키를 읽어오는 시간은 적게 걸리고 모든 데이터를 읽어오는데 시간이 오래 걸리지만 그 사이사이에 다른 요청들을 받을 수가 있으므로 레디스가 다른 요청을 처리하는데 병목이 생기는 것을 방지할 수 있습니다. 1. RedisTemplate 우선 redisTemplate을 사용하여 keys 대신 scan을.. 2022. 6. 29.
[Spring] EhCache를 Caffeine Cache로 변경하는 방법 (Caffeine Cache 적용 방법) 캐시 비교 게시글은 많기 때문에 생략하겠습니다. (Redis, EhCache, Caffeine 비교 , EhCache, Caffeine 비교) 해당 본문에서는 로컬 캐시가 EhCache로 설정되어 있는 환경을 Caffeine Cache로 변경하는 방법을 다루겠습니다. 1. pom.xml dependency를 변경합니다. ehcache caffeine net.sf.ehcache ehcache com.github.ben-manes.caffeine caffeine 3.1.1 2. application.yml ehcache 설정을 제거합니다. ehcache caffeine spring: cache: ehcache: config: classpath:cache/ehcache.xml 제거 3. Configuratio.. 2022. 6. 24.
[Spring] HttpStatus.LOCKED : 423 Client Error HTTP Status Code는 클라이언트가 보낸 HTTP 요청에 대한 서버의 응답을 코드로 표현한 것으로, 해당 코드로 요청의 성공, 실패, 실패 요인 등을 알 수 있습니다. HTTP 상태 코드 중 LOCKED 상태 코드에 대해 알아보겠습니다. Locked라는 단어만으로 단순히 잠금상태로 판단하고 계정 잠금 등에 사용하면 안 됩니다. 423 상태 코드는 메서드의 소스 또는 대상 리소스가 잠겨 있음을 의미합니다. 이 응답에는 'lock-token-submitted' 또는 'non-conflict-lock'과 같은 적절한 전제 조건 또는 사후 조건 코드가 포함되어야 합니다. 423 Locked The 423 (Locked) status code means the source or destination re.. 2022. 6. 3.
[Spring] AOP와 @EnableAspectJAutoProxy Spring AOP (Aspect Oriented Programming) AOP는 Aspect Oriented Programming의 약자로 관점 지향 프로그래밍이라고 불립니다. 쉽게 말해 관점에 따라 각각 모듈화(어떤 공통된 로직이나 기능을 하나의 단위로 묶음)하겠다는 것입니다. 소스 코드에서 여러 코드에서 반복해서 사용하는 코드를 발견할 수 있는데 이것을 흩어진 관심사(Crosscutting Concerns)라고 합니다. 흩어진 관심사를 Aspect로 모듈화하고 핵심적인 비지니스 로직에서 분리하여 재사용하겠다는 것이 AOP의 취지입니다. AOP 주요 개념 Aspect : 흩어진 관심사를 모듈화 한 것 Target : Aspect를 적용하는 곳 (ElementType 등) Advice : 실질적인 부가.. 2022. 4. 27.
[Spring] dynamic Scheduler 다이나믹 스케줄링 @ImportResource({ "classpath:scheduler/context-scheduler.xml" }) 나 @Scheduled 어노테이션을 사용하지 않고 스케줄을 동적으로 등록하는 두가지 방법을 알아보겠습니다.  1. ThreadPoolTaskScheduler꼭 아래 예시와 같이 사용할 필욘 없지만, Map에 scheduler를 저장해놓고 destroy 할 수 있습니다.@Servicepublic class SchedulerServiceImpl implements SchedulerService { private final Map schedulerMap = new ConcurrentHashMap(); public SchedulerServiceImpl() { Set typeList = ...; .. 2021. 11. 9.
[SpringBoot] Test환경에 H2 적용하기 다음과 같이 db구성이 되어있을때 Test환경에 H2 적용하는 방법입니다. https://moonsiri.tistory.com/53 [Spring] java config로 hikari datasource, transaction aop 설정 pom.xml org.springframework.boot spring-boot-starter-jdbc org.mybatis.spring.boot mybatis-spring-boot-starter 2.1.3 org.apache.commons commons-dbcp2 mysql mysql-connector-java runtime application.ym.. moonsiri.tistory.com 우선 pom.xml에 dependency를 추가합니다. com.h2datab.. 2021. 8. 4.
[SpringBoot] Reactive RESTful Web Service 구축 실습 spring.io 가이드를 참조하여 WebFlux 실습을 해보겠습니다. 개념은 이전 포스팅에서 대충 끄적인 걸로 대체하겠습니다. 목표 Spring Webflux 및 해당 서비스의 WebClient consumer로 RESTful 웹 서비스를 구축 환경 Spring Boot 2.4.2 (spring 5 이상) Maven IntelliJ openjdk 11 프로젝트 생성 우선 WebFlux 프로젝트를 생성합니다. 최초 생성 시의 pom.xml 내용입니다. 4.0.0 org.springframework.boot spring-boot-starter-parent 2.4.2 com.moonsiri reactive 0.0.1-SNAPSHOT reactive Reactive RESTful Web Service 11 o.. 2021. 2. 18.
[Spring] Reactive Programming (1) - Reactor 3, WebFlux Spring WebFlux The original web framework included in the Spring Framework, Spring Web MVC, was purpose-built for the Servlet API and Servlet containers. The reactive-stack web framework, Spring WebFlux, was added later in version 5.0. It is fully non-blocking, supports Reactive Streams back pressure, and runs on such servers as Netty, Undertow, and Servlet 3.1+ containers. 5.0 버전에 추가된 스프링 웹 플럭스.. 2021. 2. 18.
[SpringBoot] JWT 설명 및 생성, 검증 JWT JWT는 JSON Web Token의 줄임말입니다. JSON Web Token (JWT) is an open standard (RFC 7519) that defines a compact and self-contained way for securely transmitting information between parties as a JSON object. This information can be verified and trusted because it is digitally signed. JWTs can be signed using a secret (with the HMAC algorithm) or a public/private key pair using RSA or ECDSA. JWT는 웹 표준.. 2021. 1. 18.
[SpringBoot2] Lettuce Java Redis Client와 RedisCommands method 설명 Redis는 데이터베이스, 캐시 또는 메시지 브로커로 사용할 수 있는 인메모리 key-value 저장소입니다. 데이터는 Redis의 인메모리 데이터 구조에 있는 키에서 작동하여 추가, 쿼리, 수정 및 삭제됩니다. Jedis와 Lettuce의 가장 중요한 차이점은 Java 8의 CompleteStage 인터페이스를 통한 비동기식 지원 및 Reactive Streams 지원입니다. Lettuce는 Redis 데이터베이스 서버에서 비동기 요청을 하고 스트림을 생성할 수 있는 자연스러운 인터페이스를 제공합니다. 또한 서버와 통신하는 데도 사용합니다. 이렇게 하면 "무거운" API를 만들 수 있지만 둘 이상의 스레드와 연결을 공유하는 데 더 적합합니다. pom.xml에 필요한 종속성을 추가합니다. org.spri.. 2021. 1. 16.
728x90
반응형