redis
-
기존에 동시성 이슈 문제 해결을 위해 사용한 Redisson 대신 Redis의 script를 사용해서 성능 올리기SpringBoot 2024. 3. 24. 00:21
들어가며 public void issue(long couponId, long userId) { // 캐시를 통해 쿠폰에 대한 유효성 검증 수행 CouponRedisEntity coupon = couponCacheService.getCouponCache(couponId); coupon.checkIssuableCoupon(); // 레디스 동시성 이슈 해결하기 위함 distributeLockExecutor.execute("lock_%s".formatted(couponId), 3000, 3000, () -> { couponIssueRedisService.checkCouponIssueQuantity(coupon, userId); issueRequest(couponId, userId); }); } 기존에 위 메소..
-
쿠폰 발급 요청 시, 확인하는 쿠폰 정보를 Redis Cache에 담아 개선하기SpringBoot 2024. 3. 19. 23:48
들어가며 선착순 쿠폰 발급 기능 개발을 진행하고 있는데, 현재 쿠폰 발급 요청에 대한 서비스 로직에 쿠폰 발급 전에 확인하는 것 중 하나인 해당 쿠폰의 유효성 검증 부분에 개선점이 필요했습니다. Coupon coupon = couponIssueService.findCoupon(couponId); 클라이언트에서 쿠폰 발급 요청 API를 호출할 때마다, 위와 같은 방식으로 데이터베이스에 있는 couponId에 대한 쿠폰 정보를 가져와서, 쿠폰의 유효성 검증을 수행했습니다. 여기서 유효성 검증은 사용자가 쿠폰 발급을 요청한 해당 쿠폰이 발급 가능 기간에 속하는지 검증하는 단계라고 보면 됩니다. 하지만 이러한 방식은 사용자가 요청할 때마다, 데이터베이스에서 값을 조회하기 때문에 순식간에 많은 사용자가 쿠폰 발급..
-
Redis 데이터 구조Redis 2024. 2. 20. 16:26
String String 타입의 데이터 구조, 텍스트, 직렬화된 객체 등을 저장하는 용도로 자주 사용됨. SET Time complexity: O(1) Description: 지정된 key의 저장된 문자열을 저장 SET key value GET Time complexity: O(1) Description: 지정된 key의 저장된 문자열을 조회 GET key SET, GET 실습 List 데이터 삽입 순서에 따라 정렬된 문자열 컬렉션의 형태 LRANGE Time complexity: O(S + N) - S는 (HEAD or TAIL)에서의 distance, N은 지정된 요소 수 Description: List에서 지정된 범위의 요소를 반환 LRANGE key start stop LPUSH Time comp..