Skip to content

RedisClient

Jeonghun-Ban edited this page Mar 29, 2022 · 2 revisions

redis에 데이터를 저장하고 가져오고 싶다면 utils 패키지에 있는 RedisClient를 사용하면 된다.

사용 예시

@Service
public class EmailService {

  private final RedisClient redisClient;

  @Autowired
  public EmailService(redisClient RedisClient) {
    this.redisClient = redisClient;
  }

  public void genarateEmailVerify(String userName) {
    String randomNumber = (String)(Math.random() * 1000);
    String prefix = "email_verify_";
    String key = prefix + userName;
    redisClient.setValue(key, randomNumber, 15); // key, value, timeOut
  }

  public boolean confirmEmailVerify(String userName, String verifyToken){
    String prefix = "email_verify_";
    String key = prefix + userName;
    String value = redisClient.getValue(key);
    
    return value.equals(verifyToken)
  }
}
Clone this wiki locally