// 수정 전: 어디까지나 가정, 최악의 경우 무한 반복
while (authRepository.existsByUuid(createdUuid)){
createdUuid = "normal-"+ UUID.randomUUID().toString();
}
// 수정 후
int tryCnt = 0;
while (authRepository.existsByUuid(createdUuid) && tryCnt <3){
createdUuid = "normal-"+ UUID.randomUUID().toString();
tryCnt++;
}
if(tryCnt == 3){
throw new BaseException(BaseResponseStatus.ATTEMPT_LIMIT_EXCEEDED);
}
아이디 중복체크 시 동시성 문제 해결: redis에 아이디 넣어주고(?) 회원가입 되면 삭제 or unique 처리 ← while문 방식은 좋지 않음 ← exists (think)
Auth rdb에 저장된 회원값이 있는지 비교 후 동시성 처리를 위해 redis에 저장된 값이 없는지 한번 더 조회
verifyLoginId
서비스 로직에 대해 만료 시간 30분인 key 설정 후 redis 에 저장
// KeyResponseDto verifyLoginId (CheckServiceImpl.class)
// 저장 및 조회
// 저장 및 조회를 위해 id 자체를 key로 사용
if(redisTemplate.opsForValue().get(keyRequestDto.getKey()) != null){
throw new BaseException(BaseResponseStatus.ALREADY_USED_ID);
}
// 임시로 메모리에 저장 -> 회원가입 완료 시 저장
redisTemplate.opsForValue().set(keyRequestDto.getKey(), keyRequestDto.getKey(), 30, TimeUnit.MINUTES);
회원가입 처리 후 redis 에서 삭제
// void signUp (SignUpServiceImpl.class)
authRepository.save(loginRequestDto.toEntity(passwordEncoder, createdUuid));
// 회원가입 후 redis에서 아이디 삭제
redisTemplate.delete(loginRequestDto.getLoginId());