(original text from #21120)

I have implemented a dynamic Redis data source, I find a interface named LettuceClientConfigurationBuilderCustomizer that can help me build LettuceConnectionFactory using custom configuration.

However, there is an obvious disadvantage of this interface. When I try to use the method of setClientResource(), I cannot get the context information of the LettuceConnectionFactory.

This prevents me from creating Tracing(TracingContext needs tags such as hostname, database... ) in ClientResources based on the current context (such as RedisProperties).

I can submit a pull request that contains the builder interface that has been modified to add the redisProperties parameter

Comment From: pivotal-issuemaster

@zmapleshine Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

Comment From: pivotal-issuemaster

@zmapleshine Thank you for signing the Contributor License Agreement!

Comment From: philwebb

I'm afraid the change that you're suggesting cannot be made because it would break existing code.

Have you considered injecting the properties directly instead? Something like:

@Bean
public JedisClientConfigurationBuilderCustomizer myCustomizer(RedisProperties redisProperties) {
    return (builder) -> {
        // use builder and redisProperties here
    }
}

Comment From: zmapleshine

恐怕您建议的更改无法进行,因为它会破坏现有代码。

您是否考虑过直接注入属性?就像是:

java @Bean public JedisClientConfigurationBuilderCustomizer myCustomizer(RedisProperties redisProperties){ return(builder)- > { //在这里使用builder和redisProperties } }

When there is only one redis data source configuration in the system, there is no problem. If there are multiple configurations, it is not known which properties the current Builder is associated with.

I can add a default method to the customer interface, so that it will not break the existing code. E.g:

    /**
     * Customize the {@link LettuceClientConfigurationBuilder}.
     * @param properties the configuration file to which the current build belongs
     * @param clientConfigurationBuilder the builder to customize
     */
    default void customize(RedisProperties properties, LettuceClientConfigurationBuilder clientConfigurationBuilder){
        customize(clientConfigurationBuilder);
    }