springboot yml配置 redis 连接失败 RedisConnectionFailureException

 

用springboot尝试连接腾讯云服务器上的redis报错密码不匹配

目录​​​​​​​ 

使用环境

情况一

情况二

解决方法


 

使用环境

springboot 2.6.6

redis 6.2.6

 


 

情况一

密码设置成123456

连接成功

 


 

情况二

密码设置成0123456

连接失败

 redis.conf配置如下

springboot测试

报错如下 


org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis; nested exception is org.springframework.data.redis.connection.PoolException: Could not get a resource from the pool; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to 175.178.100.158/<unresolved>:6379

...

Caused by: org.springframework.data.redis.connection.PoolException: Could not get a resource from the pool; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to 175.178.100.158/<unresolved>:6379

...

Caused by: io.lettuce.core.RedisCommandExecutionException: WRONGPASS invalid username-password pair or user is disabled.

...

但是RDM连接成功

 


 

解决方法

在application.yml配置中将redis的password加上双引号

 


 

⚠️每次重新设置密码之后 记得要在服务器 重启redis!

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
Spring Boot配置Redis需要在`application.yml`文件中指定Redis连接信息。以下是一个示例: ``` spring: redis: host: localhost port: 6379 password: password # 如果Redis设置了密码,需要提供密码 ``` 如果你的Redis实例没有设置密码,则可以省略`password`属性。 在代码中使用Redis需要使用`Lettuce`或`Jedis`等Redis客户端库。以下是使用`Lettuce`连接Redis的示例: ``` @Configuration public class RedisConfig { @Value("${spring.redis.host}") private String redisHost; @Value("${spring.redis.port}") private int redisPort; @Value("${spring.redis.password}") private String redisPassword; @Bean public RedisConnectionFactory redisConnectionFactory() { RedisStandaloneConfiguration config = new RedisStandaloneConfiguration(); config.setHostName(redisHost); config.setPort(redisPort); config.setPassword(RedisPassword.of(redisPassword)); return new LettuceConnectionFactory(config); } @Bean public RedisTemplate<String, Object> redisTemplate() { RedisTemplate<String, Object> template = new RedisTemplate<>(); template.setConnectionFactory(redisConnectionFactory()); return template; } } ``` 在上面的示例中,`redisConnectionFactory`方法创建了一个`LettuceConnectionFactory`对象,并将其配置使用`application.yml`文件中指定的Redis连接信息。`redisTemplate`方法创建了一个`RedisTemplate`对象,并将其配置使用`redisConnectionFactory`方法创建的连接工厂。然后你就可以在代码中使用`RedisTemplate`对象进行Redis操作了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小叶沉迷学习

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值