项目场景:
springcloud gateway 4.1.0 集成redis
问题描述
启动报错:
Caused by: io.lettuce.core.RedisConnectionException: Unable to connect to localhost/<unresolved>:6379
Caused by: io.lettuce.core.RedisCommandExecutionException: NOAUTH Authentication required.
本地代码
1.pom
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gateway-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis-reactive</artifactId>
</dependency>
2.application.yml
spring:
application:
name: test-gateway
redis:
host: 127.0.0.1
port: 6379
password: 123456
database: 1
timeout: 50000
3.RedisConfiguration配置类
@Configuration
public class RedisConfiguration {
@Bean
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory){
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(factory);
//key序列化
redisTemplate.setKeySerializer(RedisSerializer.string());
//hash的key序列化
redisTemplate.setHashKeySerializer(RedisSerializer.string());
//value的序列化(json序列化)
redisTemplate.setValueSerializer(RedisSerializer.json());
//hash的value序列化(json序列化)
redisTemplate.setHashValueSerializer(RedisSerializer.json());
redisTemplate.afterPropertiesSet();
return redisTemplate;
}
}
原因分析:
redis配置没有问题,配置类也没有问题,百思不得其解啊,突然想到了前两天自己的总结,升级要点在于版本一定要匹配啊啊啊!既然使用的是最新的spring-boot-starter-data-redis-reactive,是不是redis服务版本的问题呢,果断下载最新windows的redis版本试试。
- redis下载地址:https://github.com/tporadowski/redis/releases,我选择 直接安装版msi
- 重启项目,搞定!!!兄弟们,再次提醒,版本升级注意版本啊!虽然是废话,嘎嘎嘎