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
Fill variables in redisson.yml with Spring Boot values. #3206
Comments
I would like to implement this, but I need some more guidance from the maintainers. In the documentation of redisson-spring-boot-starter it states that you can use "Common Spring Boot settings" or "Redisson settings". It would be nice if we can use both and merge them in some order. Or we can add some additional documentation about how the settings are prioritized (Redisson settings at the moment). We can use common Spring Boot settings to setup Redisson: spring:
redis:
secure: false
host: localhost
port: 6379
---
spring:
redis:
url: redis://localhost:6379 We can achieve the same with Redisson settings: spring:
redis:
redisson:
config: |
singleServerConfig:
address: redis://localhost:6379
---
spring:
redis:
redisson:
# Put the configuration into seperate file:
file: classpath:redisson.yaml The common Spring Boot settings allow us to dynamically (via externalized configuration) set the properties for Redisson. But there are limitations: there is only a small set of properties we can set with the common Spring Boot settings, described in The Redisson settings do not allow us to dynamically (via externalized configuration) set the properties for Redisson. But it also adds a lot of more possibilities. Just take a look at some of the server configurations (ClusterServersConfig, SingleServerConfig) that are available. These configuration let us configure Redisson very precisely, something that is not possible with the common Spring Boot settings. Can we combine the best of the two settings options: externalized configuration and precise configuration? I am thinking of the different possibilities: the seperate file for redisson.yaml is nice, but is there some Spring Boot method to include that file into the application configuration? Could we maybe add an additional field to the RedissonProperties so that we more options than only a block (starting with "|") or a file? Also what should the priority be in merging: The common Spring Boot settings, the Redisson settings. And in turn of Redisson settings, what should overwrite what? We could have file, config, and maybe an additional field. |
"Redisson settings" has priority due to limited set of common Spring Boot settings.
I'm afraid no.
No. Since we need to add all of configuration fields in this case. Which I would like to avoid. |
In this case we need to have a direct reference to |
I have implemented the following workaround for this:
Due to the order in which the classes are called it works just fine. However, I consider this more like a workaround than a proper solution. Maybe there's a better way of making the config available in the @Bean
public RedissonAutoConfigurationCustomizer redissonConfigCustomizer() {
return new RedissonAutoConfigurationCustomizer() {
private String database;
@SuppressWarnings("synthetic-access")
@Override
public void customize(Config config) {
log.info("Redisson config: {}", ToStringBuilder.reflectionToString(config, new RecursiveToStringStyle()));
RedissonConfigAccessor.setConfig(config);
}
};
} public class RedissonConfigAccessor {
private static Config config;
public static void setConfig(Config config) {
RedissonConfigAccessor.config = config;
}
public static Config getConfig() {
return config;
}
} public class ConfigEnabledRedissonRegionFactory extends RedissonRegionFactory {
@Override
protected RedissonClient createRedissonClient(Map properties) {
Config config = RedissonConfigAccessor.getConfig();
log.info("Using the existing redisson config: {}", ToStringBuilder.reflectionToString(config, new RecursiveToStringStyle()));
if (config == null) {
throw new IllegalArgumentException(
"Redisson configuration is null -> expecting configuration to be set");
}
return Redisson.create(config);
}
} |
How does your solution solves the problem of merging of two configurations - Spring Redis common config and Redisson's? |
I'm relying on the logic in I found it quite hard to understand the logic in IMO the ideal way would be to have a simple POJO that has all the possible Redisson conf values (similar to
and merging this into the single Redisson properties POJO. Maybe it would make sense to allow either This POJO could then be converted to the Redisson Probably the approach needs a bit more thinking. |
Source code deployed in maven repo.
I would like to find a way to reuse existing Config classes. |
Thanks. I found that, so I was able to understand what is happening.
I guess you could use a
Spring would automatically populate all properties using the rules mentioned in the link above. After having the initial values populated you could 'merge' it with |
Any news on this @mrniko ? It's been quite some time now since this feature request has been submitted but it does not seem to be implemented yet right ? I'm very interested in this ! |
I'm ready to consider any contribution. |
… Boot Configuration YAML
… Boot Configuration YAML Signed-off-by: Tom Scholten <Tom.Scholten@infosupport.com>
…edisson configuration
… Boot Configuration YAML Signed-off-by: Tom Scholten <Tom.Scholten@infosupport.com>
…edisson configuration Signed-off-by: Tom Scholten <Tom.Scholten@infosupport.com>
Signed-off-by: Tom Scholten <Tom.Scholten@infosupport.com>
Is your feature request related to a problem? Please describe.
We are using redisson-spring-boot-starter. We were hoping that we could configure Redisson with a redisson.yml, but also configure more dynamic properties from our application.yml.
When we run in a different environment we can overwrite the Redis hostname by setting an environment variable. With Spring Boot profiles (for example "local"), we could have an application-local.yml that contains the following:
Or set the placeholder itself:
That way we would be able to have different configurations for our local run configuration compared to what we use in our production systems. Detailed properties for Redisson (described in redisson.yml) are the same for all environment, while things like the host, port or ssl properties can change depending on the environment where the application is running.
Describe the solution you'd like
If the merging of application.yml(or application-local.yml) with redisson.yml is not possible, can we then maybe have some feature where we fill variables with Spring Boot values. That way the redisson.yml would be able to look like:
In such a way, we would be able to create an application-local.yml that looks like this:
With Spring Boot values I mean the values described by externalized configuration here. That way there are many ways to inject variables into the configuration of Redisson.
Describe alternatives you've considered
We currently are using the following as an application.yml:
This works for us but puts a lot of detail for a specific dependency in the application.yml. These fields are never changed. The values are prone to mistakes.
The text was updated successfully, but these errors were encountered: