Jedis-springboot整合redisJedis引入jedis依赖注意事项测试相关数据类型KeyStringListsethashzset案例spring boot整合redis引入相关依赖在application.properties中配置redis 配置创建redis配置类创建测试类Jedis引入jedis依赖dependency groupIdredis.clients/groupId artifactIdjedis/artifactId version3.8.0/version /dependency注意事项禁用 Linux 的防火墙:Linux(CentOs7)里执行命令systemctl stop/disable firewalld.serviceredis.conf中注释掉bind 127.0.0.1,然后protected-mode no测试相关数据类型KeyStringListsethashzset案例// 该类用于处理手机验证码的生成和验证 public class PhoneCode { public static void main(String[] args) { verifyCode(13678765435); // 从Redis获取验证码并进行验证 //getRedisCode(13678765435,993438); } // 生成一个6位的随机验证码 public static String getCode() { Random random new Random(); String code ; for (int i 0; i 6; i) { random.nextInt(10); code random.nextInt(10); } return code; } // 验证手机验证码的有效性并限制每天的发送次数 public static void verifyCode(String phone) { Jedis jedis new Jedis(192.168.24.128, 6379); String countKey phone:VerifyCode phone :count; String codeKey phone:VerifyCode phone :code; String count jedis.get(countKey); if (count null) { jedis.setex(countKey, 24 * 60 * 60, 1); } else if (Integer.parseInt(count) 2) { jedis.incr(countKey); } else if (Integer.parseInt(count) 2) { System.out.println(今天发送次数已达到上限); jedis.close(); return; } String vcode getCode(); jedis.setex(codeKey, 120, vcode); jedis.close(); } // 从Redis获取验证码并与用户输入的验证码进行比对 public static void getRedisCode(String phone,String code) { Jedis jedis new Jedis(192.168.24.128, 6379); String codeKey phone:VerifyCode phone :code; String redisCode jedis.get(codeKey); if(redisCode.equals(code)){ System.out.println(成功); }else { System.out.println(失败); } jedis.close(); } }spring boot整合redis引入相关依赖dependency groupIdorg.spr artifactIdspri /dependency dependency groupIdorg.apa artifactIdcomm version2.11.1 /dependency在application.properties中配置redis 配置创建redis配置类这里内容直接粘贴创建测试类访问本机指定地址