本地电脑启动一个springboot3.0服务,再在本地启动一个redis,这样是可以连接的,但是本地服务无法连接到外部的redis,redis配置肯定没有问题,因为我将版本转换到2.7.9就可以连接了
Start a springboot 3.0 service on the local computer, and then start a Redis locally. This allows for connection, but the local service cannot connect to external Redis. There must be no problem with Redis configuration, as I can connect by converting the version to 2.7.9
Comment From: wilkinsona
but the local service cannot connect to external Redis
How does it fail? Please share the log output that's produced.
There must be no problem with Redis configuration, as I can connect by converting the version to 2.7.9
Spring Boot 3.0 has upgraded to new versions of both Jedis and Lettuce. Which one are you using?
Comment From: wangtianruipopo
org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis
at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$ExceptionTranslatingConnectionProvider.translateException(LettuceConnectionFactory.java:1602) ~[spring-data-redis-3.1.0.jar:3.1.0]
at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$ExceptionTranslatingConnectionProvider.getConnection(LettuceConnectionFactory.java:1533) ~[spring-data-redis-3.1.0.jar:3.1.0]
at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$SharedConnection.getNativeConnection(LettuceConnectionFactory.java:1358) ~[spring-data-redis-3.1.0.jar:3.1.0]
at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$SharedConnection.getConnection(LettuceConnectionFactory.java:1341) ~[spring-data-redis-3.1.0.jar:3.1.0]
at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.getSharedReactiveConnection(LettuceConnectionFactory.java:1083) ~[spring-data-redis-3.1.0.jar:3.1.0]
at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.getReactiveConnection(LettuceConnectionFactory.java:479) ~[spring-data-redis-3.1.0.jar:3.1.0]
at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.getReactiveConnection(LettuceConnectionFactory.java:105) ~[spring-data-redis-3.1.0.jar:3.1.0]
at reactor.core.publisher.MonoSupplier.call(MonoSupplier.java:67) ~[reactor-core-3.5.6.jar:3.5.6]
at reactor.core.publisher.FluxSubscribeOnCallable$CallableSubscribeOnSubscription.run(FluxSubscribeOnCallable.java:227) ~[reactor-core-3.5.6.jar:3.5.6]
at reactor.core.scheduler.SchedulerTask.call(SchedulerTask.java:68) ~[reactor-core-3.5.6.jar:3.5.6]
at reactor.core.scheduler.SchedulerTask.call(SchedulerTask.java:28) ~[reactor-core-3.5.6.jar:3.5.6]
at java.base/java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:264) ~[na:na]
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java) ~[na:na]
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[na:na]
at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]
Caused by: io.lettuce.core.RedisConnectionException: Unable to connect to localhost/<unresolved>:6379
at io.lettuce.core.RedisConnectionException.create(RedisConnectionException.java:78) ~[lettuce-core-6.2.4.RELEASE.jar:6.2.4.RELEASE]
at io.lettuce.core.RedisConnectionException.create(RedisConnectionException.java:56) ~[lettuce-core-6.2.4.RELEASE.jar:6.2.4.RELEASE]
at io.lettuce.core.AbstractRedisClient.getConnection(AbstractRedisClient.java:350) ~[lettuce-core-6.2.4.RELEASE.jar:6.2.4.RELEASE]
at io.lettuce.core.RedisClient.connect(RedisClient.java:216) ~[lettuce-core-6.2.4.RELEASE.jar:6.2.4.RELEASE]
at org.springframework.data.redis.connection.lettuce.StandaloneConnectionProvider.lambda$getConnection$1(StandaloneConnectionProvider.java:112) ~[spring-data-redis-3.1.0.jar:3.1.0]
at java.base/java.util.Optional.orElseGet(Optional.java:364) ~[na:na]
at org.springframework.data.redis.connection.lettuce.StandaloneConnectionProvider.getConnection(StandaloneConnectionProvider.java:112) ~[spring-data-redis-3.1.0.jar:3.1.0]
at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$ExceptionTranslatingConnectionProvider.getConnection(LettuceConnectionFactory.java:1531) ~[spring-data-redis-3.1.0.jar:3.1.0]
... 15 common frames omitted
Caused by: io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: no further information: localhost/127.0.0.1:6379
Caused by: java.net.ConnectException: Connection refused: no further information
at java.base/sun.nio.ch.Net.pollConnect(Native Method) ~[na:na]
at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:672) ~[na:na]
at java.base/sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:946) ~[na:na]
at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:337) ~[netty-transport-4.1.92.Final.jar:4.1.92.Final]
at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:334) ~[netty-transport-4.1.92.Final.jar:4.1.92.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:776) ~[netty-transport-4.1.92.Final.jar:4.1.92.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724) ~[netty-transport-4.1.92.Final.jar:4.1.92.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650) ~[netty-transport-4.1.92.Final.jar:4.1.92.Final]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562) ~[netty-transport-4.1.92.Final.jar:4.1.92.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997) ~[netty-common-4.1.92.Final.jar:4.1.92.Final]
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.92.Final.jar:4.1.92.Final]
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.92.Final.jar:4.1.92.Final]
at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]
@wilkinsona Connecting to Redis on one's own computer is sufficient, but connecting to external Redis, i.e. Redis not on one's own computer, is not sufficient But spring boot version 2.7.9 can connect normally 3.0 and above failed with this error reported
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency>
This is my pom file
Comment From: wilkinsona
Have you updated your Redis configuration properties, as described in the migration guide?
Comment From: wangtianruipopo
spring: data: redis: host: lms-cloud-redis #服务器地址 你服务器或本机地址 port: 6379 #连接端口 database: 0 #数据库索引,默认0 password: 000415 #密码 jedis: pool: max-active: 8 #连接池最大连接数(使用负值表示没有限制) max-wait: -1 #最大阻塞等待时间(使用负值表示没有限制) max-idle: 8 #最大空闲连接数 min-idle: 0 #最小空闲连接数 timeout: 5000 #连接超时时间(毫秒) @wilkinsona Is this right? Still reporting the same error
Comment From: wilkinsona
Yes, that looks right.
If you would like us to spend some more time investigating, please spend some time providing a complete yet minimal sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.
Comment From: wangtianruipopo
The reason has been found, and single quotation marks must be added to the password settings
spring: data: redis: password: '000415'
Comment From: clayly
The reason has been found, and single quotation marks must be added to the password settings
spring: data: redis: password: '000415'
@wilkinsona Looks like breaking change somewhere? We passing password through envionment variables and such change breaked our deploy. Don't you know where this change comes from?
Comment From: wilkinsona
@clayly Environment variables should not be affected, AFAIK. The problem in @wangtianruipopo's case was the use of YAML. Without the quotes, 000415 is treated as the number 415. When quoted, '000415' is treated as the string 000415. YAML isn't involved with environment variables so the value should not be affected by YAML's behavior.
Comment From: clayly
@clayly Environment variables should not be affected, AFAIK. The problem in @wangtianruipopo's case was the use of YAML. Without the quotes,
000415is treated as the number415. When quoted,'000415'is treated as the string000415. YAML isn't involved with environment variables so the value should not be affected by YAML's behavior.
After upgrading from id("org.springframework.boot") version "3.0.5" -> "3.1.0" server no longer connects to Redis (neither in tests with testcontainers nor if deployed to AWS nor to localhost redis), so i searching for possible reasons. Lettuce is used.
Comment From: wilkinsona
@clayly Please open a new issue with a minimal sample that reproduces the behavior you have described and we will take a look.
Comment From: nitelite
@clayly I got a similar issue after upgrading to 3.1.2. On the previous version I was able to connect without specifically enabling SSL. With 3.1.2 I had to add the following to my config keys to enable SSL (since the port I have specified is an SSL port):
ssl:
enabled: true
Full example of config after it started working:
spring;
data:
redis:
host: <host>
port: 6380
password: <password>
database: <database num>
ssl:
enabled: true
Comment From: clayly
@clayly I got a similar issue after upgrading to 3.1.2. On the previous version I was able to connect without specifically enabling SSL. With 3.1.2 I had to add the following to my config keys to enable SSL (since the port I have specified is an SSL port):
ssl: enabled: trueFull example of config after it started working:
spring; data: redis: host: <host> port: 6380 password: <password> database: <database num> ssl: enabled: true
Thank you, will try.
Comment From: RobertChaw
I encountered the same problem and solved by this issue. Thanks
Comment From: spongehah
Now I have the same problem, the project starts normally when I configure with the native application.yml file, but when I configure application.yml with nacos config, the redis connection fails springboot version:3.0.4
Comment From: euics
I'm having the same problem. I am using Springboot version 3.1.6 and the settings in the yml file are as below, but an "Unable to connect to Redis" error occurs.
data:
redis:
host: localhost
port: 6379
ssl:
enabled: true
Comment From: wilkinsona
@euics, that's the wrong property. You're setting data.redis.host and data.redis.port, the correct YAML would be:
spring:
data:
redis:
host: localhost
port: 6379
ssl:
enabled: true
Also, please note that this configuration is the same as the defaults. If it's not working, that suggests that the problem is at the Redis server end not the client end. As such, I don't think this is likely to be a Spring Boot bug and Stack Overflow is a better place to get the help that you're asking for.
Comment From: willchan23
I change my pwd to the shape like 'xxxxxx' but it doesn't work either, this is my application.yml
Spring:
redis:
data:
database: 1
host: 192.168.111.128
port: 6379
password: 'xxxxxxxxxxxxx'
lettuce:
pool:
max-active: 8
max-idle: 8
min-idle: 0
min-wait: 100
application:
name: redis
thank you! I am a beginner in the springboot and redis.
Comment From: wilkinsona
@willchan23 Please post a question on Stack Overflow that provides more details about your configuration and the failure that you're seeing.
Comment From: willchan23
Thanks! The test code
package org.example.redis;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;
@SpringBootTest
public class SpringData {
@Autowired
private RedisTemplate redisTemplate;
@Test
void testString(){
//写入一条string数据
redisTemplate.opsForValue().set("name", "虎哥");
Object name = redisTemplate.opsForValue().get("name");
System.out.println("name = " +name);
}
}
And I want to use the RedisTemplate to link the redis, my application.yml :
spring:
redis:
data:
host: 192.168.111.128
port: 6379
password: xxxxxxxxx
lettuce:
pool:
max-active: 8
max-idle: 8
min-idle: 0
min-wait: 100
application:
name: redis
the redis server started in VMware liunx, and when i use the jedis rather than the RedisTemplate, it works with redis successful. The error:
Caused by: org.springframework.data.redis.connection.PoolException: Could not get a resource from the pool
at org.springframework.data.redis.connection.lettuce.LettucePoolingConnectionProvider.getConnection(LettucePoolingConnectionProvider.java:104)
at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$ExceptionTranslatingConnectionProvider.getConnection(LettuceConnectionFactory.java:1776)
... 17 more
Comment From: wilkinsona
As I said above, please post a question on Stack Overflow.