We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1. @PostMapping("/redis-stock/purchase") public Response<Void> purchase(@RequestBody StockAdapterDto request) { redisStockService.purchase(request); return Response.success(); } 2. public void purchase(StockAdapterDto stockAdapterDto) { redisStockRepository.decrementStock(stockAdapterDto.productId(), stockAdapterDto.quantity()); } 3. public void decrementStock(Long productId, Integer quantity) { String key = getKey(productId); RedisStock redisStock = redisTemplate.opsForValue().get(key); redisStock.verifyRemainAvailability(quantity); redisStock.setRemain(redisStock.getRemain() - quantity); redisTemplate.opsForValue().set(key, redisStock); }
Redis inventory classes are:
@Getter @Setter @AllArgsConstructor @NoArgsConstructor public class RedisStock implements Serializable { private Long productId; private Integer remain; public void verifyRemainAvailability(final Integer quantity) { if ((remain - quantity) < 0) { throw new IllegalArgumentException(); } remain -= quantity; } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Redis inventory classes are:
The text was updated successfully, but these errors were encountered: