요약
레디스 실행
docker pull redis
docker run --name myredis -d -p 6379:6379 redis
스프링에 레디스 의존성 추가
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
아래 apply 메서드에서 race condition이 발생한다.
@Service
public class ApplyService {
private final CouponRepository couponRepository;
@Transactional
public void apply(Long userId) {
long count = couponRepository.count();
if (count > 100) {
return;
}
couponRepository.save(new Coupon(userId));
}
}