1.环境要求:
1. redis配置文件redis.conf要求:
1.protected-mode no
2.注释掉bind 127.0.0.1
3.设置timeout 不为0
2.vm与主机能互相ping通
3.虚拟机上开放了端口,各种虚拟机的开发方式不同,百度指令开发即可
2.springboot连接时要求在application.yml配置redis正确的服务器ip,timeout时间不为0
3.springboot2.x中使用依赖lettuce,且lettuce不发心跳检测,而springboot1.x用的依赖是jedis,
这个会报io.lettuce的异常,
springboot2.x原版:
springboot旧版依赖:
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-redis</artifactId> </dependency> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> </dependency> </dependencies>
解决方式:
修改pom.xml,在启动器依赖上替换:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<exclusions>
<exclusion>
<groupId>io.lettuce</groupId>
<artifactId>lettuce-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</dependency>