Skip to content

Redis standalone can't use application.properties to change Redis configuration #2914

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
UnfetteredCodeMan opened this issue May 19, 2024 · 4 comments
Labels
status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged

Comments

@UnfetteredCodeMan
Copy link

Can't change the Redis startup port by modifying the application.properties's host,port,password when using RedisTemplate on Redis standalone.
bedced2a45f8e98e73546c1b22f7e3c
image

But I can connect to the Redis server by way of RedisStandaloneConfiguration
image

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?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 19, 2024
@mp911de
Copy link
Member

mp911de commented May 21, 2024

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.

@mp911de mp911de added the status: waiting-for-feedback We need additional information before we can continue label May 21, 2024
@UnfetteredCodeMan
Copy link
Author

UnfetteredCodeMan commented May 21, 2024

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:

  1. org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis
  2. Unable to connect to localhost/:6379
  3. 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

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels May 21, 2024
@josue270193
Copy link

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.

@kwleungaj
Copy link

kwleungaj commented Jun 6, 2025

Hi, I've encountered the same issue using Spring Boot 3.4.5. I tried both spring.redis.host and spring.data.redis.host in application.yml, and I also attempted to set up environment variables, but neither approach worked. It was still connecting to localhost:6379. I tried @UnfetteredCodeMan approach to use RedisStandaloneConfiguration and solved the problem.

@Bean
public RedisConnectionFactory redisConnectionFactory() {
    RedisStandaloneConfiguration serverConfig = new RedisStandaloneConfiguration("redis", 6379);
    return new LettuceConnectionFactory(serverConfig);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

5 participants