Commit 0194e6f2 by zhoujinghao

reids 提交

1 parent c39b13a8
...@@ -15,12 +15,16 @@ import org.nafmii.common.utils.GuavaUtil; ...@@ -15,12 +15,16 @@ import org.nafmii.common.utils.GuavaUtil;
import org.nafmii.common.utils.JwtUtils; import org.nafmii.common.utils.JwtUtils;
import org.nafmii.common.utils.SnowFlakeUtil; import org.nafmii.common.utils.SnowFlakeUtil;
import org.nafmii.common.constant.UserEnum; import org.nafmii.common.constant.UserEnum;
import org.nafmii.enums.RedisEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit;
/** /**
* @author:zhoujh * @author:zhoujh
...@@ -36,6 +40,12 @@ public class UserServiceImpl implements UserService { ...@@ -36,6 +40,12 @@ public class UserServiceImpl implements UserService {
@Resource @Resource
private AppUserMapper appUserMapper; private AppUserMapper appUserMapper;
//redis缓存快递集合-key
public static final String USER_CODE_KEY="user:code";
@Autowired
StringRedisTemplate stringRedisTemplate;
/** /**
* 模拟用户登陆 * 模拟用户登陆
* @return * @return
...@@ -99,8 +109,9 @@ public class UserServiceImpl implements UserService { ...@@ -99,8 +109,9 @@ public class UserServiceImpl implements UserService {
log.info("用户注册参数==============>"+registerDto); log.info("用户注册参数==============>"+registerDto);
//将验证码放入到缓存当中(过期时间60s)test //将验证码放入到缓存当中(过期时间60s)test
// GuavaUtil.putTrackGuava(registerDto.getPhone(),registerDto.getCode()); // GuavaUtil.putTrackGuava(registerDto.getPhone(),registerDto.getCode());
stringRedisTemplate.opsForValue().set(new StringBuilder().append(USER_CODE_KEY).append(registerDto.getPhone()).toString(), registerDto.getCode(), RedisEnum.PHONECODE.getCode(), TimeUnit.SECONDS);
//重缓存中获取(通过手机号获取) //重缓存中获取(通过手机号获取)
String code = (String) GuavaUtil.getTrackGuava(registerDto.getPhone()); String code = stringRedisTemplate.opsForValue().get(USER_CODE_KEY+registerDto.getPhone());
log.info("冲缓存中获取的验证码===============》{}",code); log.info("冲缓存中获取的验证码===============》{}",code);
if (null == code){ if (null == code){
throw new BusinessException("验证码已过期"); throw new BusinessException("验证码已过期");
...@@ -133,7 +144,8 @@ public class UserServiceImpl implements UserService { ...@@ -133,7 +144,8 @@ public class UserServiceImpl implements UserService {
} }
}else{ }else{
//验证码登陆 //验证码登陆
String code = (String) GuavaUtil.getTrackGuava(loginDto.getPhone()); String code = stringRedisTemplate.opsForValue().get(USER_CODE_KEY+loginDto.getPhone());
log.info("冲redis中获取的验证码===============》{}",code);
log.info("冲缓存中获取的验证码===============》{}",code); log.info("冲缓存中获取的验证码===============》{}",code);
if (null == code){ if (null == code){
throw new BusinessException("验证码已过期"); throw new BusinessException("验证码已过期");
......
...@@ -26,4 +26,20 @@ spring: ...@@ -26,4 +26,20 @@ spring:
driver-class-name: com.mysql.cj.jdbc.Driver driver-class-name: com.mysql.cj.jdbc.Driver
password: Moxi123# password: Moxi123#
url: jdbc:mysql://114.112.96.30:30029/NAFMII_2.1?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC url: jdbc:mysql://114.112.96.30:30029/NAFMII_2.1?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
username: root
\ No newline at end of file \ No newline at end of file
username: root
redis:
# Redis数据库索引(默认为0)
database: 0
# Redis服务器地址
host: 127.0.0.1
port: 6379
# Redis服务器连接密码(默认为空)
password:
jedis:
pool:
# 连接池最大连接数(使用负值表示没有限制)
max-active: 20
max-wait: -1ms
max-idle: 10
min-idle: 0
timeout: 1000ms
package org.nafmii.enums;
/**
* @author:zhoujh
* @Function:TODO
* @date 2021/4/27 13:48
* @ClassName:
* @version:
* @remark:
*/
public enum RedisEnum {
/**
* 验证码失效时间60s
*/
PHONECODE(60, "60秒后失效")
;
RedisEnum(Integer code, String name){
this.code = code;
this.name = name;
}
private String name;
private Integer code;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!