상황 설명

@Scheduled(cron = "0 0 0 * * *")
@Transactional
private void schedulingOpenRunProduct() throws InterruptedException{
    updateProductStatus();
    Long count = saveOpenRunCount();
		saveOpenRunRedisCache(count);
    saveAllProductCount();    
}

//....

private void saveOpenRunRedisCache(Long count){
	long totalPages = count / 16; // 17 => 1.xx  0, 1

	for (int i = 0; i <= totalPages; i++) {
	    Pageable pageable = PageRequest.of(i, 16);
	    openRunProductRedisRepository.saveProduct(i, productRepository.findOpenRunProducts(OpenRunStatus.OPEN, pageable, count));
	}
}

개선 사항

결과

<aside> 💡 Spring Batch 적용 ⬇️

</aside>

@Bean
public Job productJob(
        JobRepository jobRepository,
        Step openRunProductUpdateStep,
        Step openRunCountStep,
        Step openRunSaveRedisStep,
        Step saveAllProductCountStep) {
    return new JobBuilder("productJob", jobRepository)
            .start(openRunProductUpdateStep)
            .on("FAILED").to(openRunCountStep)
            .from(openRunProductUpdateStep).on("*").to(openRunCountStep)

            .from(openRunCountStep)
            .on("FAILED").to(openRunSaveRedisStep)
            .from(openRunCountStep).on("*").to(openRunSaveRedisStep)

            .from(openRunSaveRedisStep)
            .on("FAILED").to(saveAllProductCountStep)
            .from(openRunSaveRedisStep).on("*").to(saveAllProductCountStep)

            .end()
            .build();
}