Spring 2 到 Spring 3 迁移后 Redis 报错 NOAUTH 错误的原因及解决?

新手上路,请多包涵

Spring2 转到 Spring3 后整合 Redis 报错 NOAUTH Authentication required

我在spring boot 2.7.3中使用SpringDataRedis正常运行。

但在spring boot 3.4.0中使用就会报错NOAUTH Authentication required.

Redis版本: 3.2.100-windows版

依赖:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>

配置类:

@Configuration
public class RedisConfiguration {

    @Bean
    public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory) {
        RedisTemplate redisTemplate = new RedisTemplate<>();

        // 设置 Redis 的连接工厂对象
        redisTemplate.setConnectionFactory(redisConnectionFactory);
        // 设置 Redis key 的序列化器
        redisTemplate.setKeySerializer(new StringRedisSerializer());

        return redisTemplate;
    }

}

spring boot 3.4.0 的 application (相较于2.7.3增加了data):

# Redis 主机地址
spring.data.redis.host=localhost
# Redis 端口号
spring.data.redis.port=6379
# Redis 密码
spring.data.redis.password=123456
# Redis 指定数据库
spring.data.redis.database=1

redis.windows.conf中将密码注释,并注释 application 中的spring.data.redis.password=123456后,能够成功运行。

猜测是因为 spring 版本太高而 redis 版本太低的原因?

阅读 1.8k
1 个回答

redis 3.0 版本仅支持 RESP2 的通信协议,而 Lettuce 6.x 版本开始,使用 RESP3(Redis 6.x 引入)的 HELLO 命令进行版本自适应判断,但是对于不支持 HELLO 命令的低版本实例,兼容性存在一定问题。刚好 springboot 版本默认的引入的 redis 客户端是 lettuce 6.x ,协议不通。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏