Redis standalone can't use application.properties to change Redis configuration
UnfetteredCodeMan opened this issue · 3 comments
Can't change the Redis startup port by modifying the application.properties's host,port,password when using RedisTemplate on Redis standalone.
But I can connect to the Redis server by way of RedisStandaloneConfiguration
So is spring-boot-starter-data-redis with version 3.2.5 unable to configure Redis startup configurations by modifying configuration files such as application.properties?
If you would like us to spend some time helping you to diagnose the problem, please spend some time describing it and, ideally, providing a minimal yet complete 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.
This is my redis configuration class
@Configuration
class MyConfig {
@Bean
LettuceConnectionFactory connectionFactory() {
return new LettuceConnectionFactory();
}
@Bean
ReactiveRedisTemplate<String, String> ReactiveRedisTemplate(ReactoveRedisConnectionFactory connectionFactory) {
return new ReactiveRedisTemplate<>(connectionFactory, RedisSerializationContext.string());
}
}
This is my project maven environment
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis-reactive</artifactId>
</dependency>
</dependencies>
And I configured the host,password&port in application.properties
spring.data.redis.host=xxx.com
spring.data.redis.port=14777
spring.data.redis.password=xxxxx
Then I wrote a test case intending to pass a list data to my Redis remote server
@Qualifier("ReactiveRedisTemplate")
@Autowired
private ReactiveRedisOperations<String, String> operations;
public Mono<Long> addLink(String userId, String url) {
return operations.opsForList().leftPush(userId, url);
}
@Test
void testA() {
Mono<Long> mono = addLink("tks1", "http://google.com");
log.info("mono: {}", mono.block());
}
And then an error.The error message is as follows:
- org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis
- Unable to connect to localhost/:6379
- Connection refused: no further information: localhost/127.0.0.1:6379
But I can connect to the Redis server by way of RedisStandaloneConfiguration:
@Configuration
class MyConfig {
@Bean
LettuceConnectionFactory connectionFactory() {
RedisStandaloneConfiguration serverConfig = new RedisStandaloneConfiguration("xxx.com", 14777);
serverConfig.setPassword("xxxxx");
return new LettuceConnectionFactory(serverConfig, clientConfig);
}
@Bean
ReactiveRedisTemplate<String, String> ReactiveRedisTemplate(ReactoveRedisConnectionFactory connectionFactory) {
return new ReactiveRedisTemplate<>(connectionFactory, RedisSerializationContext.string());
}
}
Then the data was uploaded successfully
INFO 3296 --- [ main] p.l.LearnSpringBootApplicationTest : mono: 1
So, spring-boot-starter-data-redis with version 3.2.5 unable to configure Redis startup configurations by modifying configuration files such as application.properties?
@mp911de
Hello, I'm having the same issue. I did what @UnfetteredCodeMan mentions to solved my problem, using the application.properties doesn't work at all. In my case, I use spring boot 3.3.0 and redisStandalone.