成都建网站的公司,企业网站关键词优化,深圳市华强北,网站被收录后又被提出了Jedis-springboot整合redis
Jedis
引入jedis依赖
注意事项
测试相关数据类型
Key
String
List
set
hash
zset
案例
spring boot整合redis
引入相关依赖
在application.properties中配置redis 配置
创建redis配置类
创建测试类 Jedis
引入jedis依赖
depen…Jedis-springboot整合redis
Jedis
引入jedis依赖
注意事项
测试相关数据类型
Key
String
List
set
hash
zset
案例
spring boot整合redis
引入相关依赖
在application.properties中配置redis 配置
创建redis配置类
创建测试类 Jedis
引入jedis依赖
dependencygroupIdredis.clients/groupIdartifactIdjedis/artifactIdversion3.8.0/version
/dependency
注意事项
禁用 Linux 的防火墙:Linux(CentOs7)里执行命令systemctl stop/disable firewalld.service
redis.conf中注释掉 bind 127.0.0.1,然后 protected-mode no
测试相关数据类型
Key String List set hash zset 案例 // 该类用于处理手机验证码的生成和验证
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
引入相关依赖
dependencygroupIdorg.sprartifactIdspri
/dependency
dependencygroupIdorg.apaartifactIdcommversion2.11.1
/dependency
在application.properties中配置redis 配置 创建redis配置类
这里内容直接粘贴 创建测试类 访问本机指定地址