[redisson]redisson-spring-boot-starter能否直接增加json字符串或者yaml字符串配置而不仅仅只是增加配置文件config路径的配置

2024-07-18 602 views
0
Expected behavior Actual behavior Steps to reproduce or test case Redis version Redisson version Redisson configuration

这样子有利于配置中心更好的动态配置

回答

2

能仔细解释一下吗?

4

public class RedissonProperties {

private String config;

private String json;

private String yaml;

public String getConfig() {
    return config;
}

public void setConfig(String config) {
    this.config = config;
}

public String getJson() {
    return json;
}

public void setJson(String json) {
    this.json = json;
}

public String getYaml() {
    return yaml;
}

public void setYaml(String yaml) {
    this.yaml = yaml;
}

}

if (redissonProperties.getJson() != null) { config = Config.fromJSON(redissonProperties.getJson()); } else if (redissonProperties.getYaml() != null) { config = Config.fromYAML(redissonProperties.getYaml()); } else if (redissonProperties.getConfig() != null) {

7

这样子才能完整的使用Redisson的配置,不然只能使用部分spring-data-redis的基础配置

0

你试试把json文件的内容换成变量,然后利用Property Overrides去赋值。你可以参照https://github.com/redisson/redisson/blob/master/redisson/src/main/java/org/redisson/config/ConfigSupport.java#L138 了解一下原理。

1

其实我只是不想通过文件存储Json或者Yaml再读取,而是直接通过json或者yaml的字符串来保存整个json或者yaml的配置,比如通过变量配置Cluster模式,在RedissonAutoConfiguration里面的源码如下: config = new Config(); config.useClusterServers() .addNodeAddress(nodes) .setConnectTimeout(timeout) .setPassword(redisProperties.getPassword()); 如果我想要设置Codec应该如何设置?

7

首先路径可以是URL,不一定必须是本地文件。 其次文件内容会先读成字符串,然后经过一次变量解析,最后再去反序列化。你可以以URL的形式提供配置文件,也可以把整个文件内容设为一个变量,然后通过Property Overrides去赋值它。

8

好的 谢谢