레디스를 이용해서 동시 요청 방지하기
Last updated
Last updated
@Component
@RequiredArgsConstructor
public class RedisRepository {
private final RedisTemplate<String, String> redisTemplate;
public boolean isDuplciated(final String key) {
var ops = redisTemplate.boundValueOps(key);
var result = ops.increment(1L);
// result can be null
if (result == null || result == 1L) {
// this ops wil expire in 1 seconds
ops.expire(1, TimeUnit.SECONS)
return false;
}
return true;
}
}