You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.3 KiB

6 years ago
/**
* Copyright (c) 2018 人人开源 All rights reserved.
*
* https://www.renren.io
*
* 版权所有侵权必究
*/
package com.epmet.redis;
import com.epmet.commons.tools.redis.RedisKeys;
import com.epmet.commons.tools.redis.RedisUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
6 years ago
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* 验证码Redis
*
* @author Mark sunlightcs@gmail.com
* @since 1.0.0
*/
@Component
public class CaptchaRedis {
private Logger logger = LogManager.getLogger(CaptchaRedis.class);
6 years ago
/**
* 验证码5分钟过期
*/
private final static long EXPIRE = 60 * 5L;
@Autowired
private RedisUtils redisUtils;
public void set(String uuid, String captcha){
String key = RedisKeys.getLoginCaptchaKey(uuid);
logger.info("保存验证码key=["+key+"]");
6 years ago
redisUtils.set(key, captcha, EXPIRE);
}
public String get(String uuid){
String key = RedisKeys.getLoginCaptchaKey(uuid);
String captcha = (String)redisUtils.get(key);
logger.info("获取验证码key=["+key+"]captcha=["+captcha+"]");
6 years ago
//删除验证码
if(captcha != null){
redisUtils.delete(key);
}
return captcha;
}
}