题主在测试spingdata连接redis时,遇到了
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 localhost:6379
这个错误
其中测试文件为
class SpringDataRedisApplicationTests {
@Autowired
private RedisTemplate redisTemplate;
@Test
void contextLoads() {
}
@Test
void writeTest(){
redisTemplate.opsForValue().set("keyTest", "valueTest");
String keyTest = (String)redisTemplate.opsForValue().get("keyTest");
System.out.println("The name is " + keyTest);
}
}
redis配置为
spring:
data:
redis:
host: 192.168.188.100
port: 6379
password: 123456
lettuce:
pool:
max-active: 8
max-idle: 8
min-idle: 0
max-wait: 1000ms
查找了一会原因后,发现是redis配置的问题
spring.data.redis这个redis配置方式是springboot3.x后才开始引入的,而题主用的是springboot2.7,将redis配置改为spring.redis…后问题得到解决
spring:
redis:
host: 192.168.188.100
port: 6379
password: 123456
lettuce:
pool:
max-active: 8
max-idle: 8
min-idle: 0
max-wait: 1000ms
在测试SpringDataRedis连接时遇到RedisConnectionFailureException,原因是使用了SpringBoot3.x的配置方式,而在SpringBoot2.7中应使用spring.redis的配置。修改配置后,问题得到解决。
1万+

被折叠的 条评论
为什么被折叠?



