1.注入Redis
@Resource
RedisTemplate<String, String> redisTemplate;
2.存入验证码
String code = Integer.toString((int) ((Math.random() * 9 + 1) * 100000));
System.out.println(code);
redisTemplate.opsForValue().set(card,code,60, TimeUnit.SECONDS);
return new JsonResult<>(“获取验证码成功,一分钟内有效”);
其中opsForValue()用来存入字符串,还有Hash,List,Set存储类型
附上设置key过期时间用法