Search in sources :

Example 1 with ReplicatedServersConfig

use of org.redisson.config.ReplicatedServersConfig in project LinkAgent by shulieTech.

the class RedissonFactory method getAddr.

public List<String> getAddr(Config config) {
    SingleServerConfig singleServerConfig = Reflect.on(config).get(RedissonConstants.DYNAMIC_FIELD_SINGLE_SERVER_CONFIG);
    ClusterServersConfig clusterServersConfig = Reflect.on(config).get(RedissonConstants.DYNAMIC_FIELD_CLUSTER_SERVERS_CONFIG);
    SentinelServersConfig sentinelServersConfig = Reflect.on(config).get(RedissonConstants.DYNAMIC_FIELD_SENTINEL_SERVERS_CONFIG);
    ReplicatedServersConfig replicatedServersConfig = Reflect.on(config).get(RedissonConstants.DYNAMIC_FIELD_REPLICATED_SERVERS_CONFIG);
    MasterSlaveServersConfig masterSlaveServersConfig = Reflect.on(config).get(RedissonConstants.DYNAMIC_FIELD_MASTER_SLAVE_SERVERS_CONFIG);
    if (singleServerConfig != null) {
        return RedissonUtils.removePre(singleServerConfig.getAddress());
    } else if (clusterServersConfig != null) {
        return RedissonUtils.removePre(clusterServersConfig.getNodeAddresses());
    } else if (replicatedServersConfig != null) {
        return RedissonUtils.removePre(replicatedServersConfig.getNodeAddresses());
    } else if (masterSlaveServersConfig != null) {
        Set slave = masterSlaveServersConfig.getSlaveAddresses();
        List<String> result = new ArrayList(RedissonUtils.removePre(slave));
        Object master = masterSlaveServersConfig.getMasterAddress();
        result.addAll(RedissonUtils.removePre(master));
        return result;
    }
    return null;
}
Also used : ReplicatedServersConfig(org.redisson.config.ReplicatedServersConfig) Set(java.util.Set) ClusterServersConfig(org.redisson.config.ClusterServersConfig) SentinelServersConfig(org.redisson.config.SentinelServersConfig) ArrayList(java.util.ArrayList) SingleServerConfig(org.redisson.config.SingleServerConfig) ArrayList(java.util.ArrayList) List(java.util.List) MasterSlaveServersConfig(org.redisson.config.MasterSlaveServersConfig)

Example 2 with ReplicatedServersConfig

use of org.redisson.config.ReplicatedServersConfig in project LinkAgent by shulieTech.

the class RedissonNodesStrategy method getAddress.

public static List getAddress(Config config) {
    SingleServerConfig singleServerConfig = null;
    try {
        singleServerConfig = Reflect.on(config).get(RedissonConstants.DYNAMIC_FIELD_SINGLE_SERVER_CONFIG);
    } catch (ReflectException e) {
    }
    ClusterServersConfig clusterServersConfig = null;
    try {
        clusterServersConfig = Reflect.on(config).get(RedissonConstants.DYNAMIC_FIELD_CLUSTER_SERVERS_CONFIG);
    } catch (ReflectException e) {
    }
    SentinelServersConfig sentinelServersConfig = null;
    try {
        sentinelServersConfig = Reflect.on(config).get(RedissonConstants.DYNAMIC_FIELD_SENTINEL_SERVERS_CONFIG);
    } catch (ReflectException e) {
    }
    ReplicatedServersConfig replicatedServersConfig = null;
    try {
        replicatedServersConfig = Reflect.on(config).get(RedissonConstants.DYNAMIC_FIELD_REPLICATED_SERVERS_CONFIG);
    } catch (ReflectException e) {
    }
    MasterSlaveServersConfig masterSlaveServersConfig = null;
    try {
        masterSlaveServersConfig = Reflect.on(config).get(RedissonConstants.DYNAMIC_FIELD_MASTER_SLAVE_SERVERS_CONFIG);
    } catch (ReflectException e) {
    }
    if (singleServerConfig != null) {
        // 在这里返回的address在不同版本可能返回String,可能返回URI在这里做处理
        Object address = Reflect.on(singleServerConfig).get("address");
        String addressConvert = null;
        if (address instanceof URI) {
            URI uriConvert = (URI) address;
            addressConvert = RedissonUtils.addPre(new StringBuilder().append(uriConvert.getHost()).append(":").append(uriConvert.getPort()).toString());
        } else if (address instanceof String) {
            addressConvert = (String) address;
        }
        return RedissonUtils.removePre(addressConvert);
    } else if (clusterServersConfig != null) {
        return RedissonUtils.removePre(clusterServersConfig.getNodeAddresses());
    } else if (sentinelServersConfig != null) {
        List<String> result = RedissonUtils.removePre(sentinelServersConfig.getSentinelAddresses());
        result.add(sentinelServersConfig.getMasterName());
        return result;
    } else if (replicatedServersConfig != null) {
        return RedissonUtils.removePre(replicatedServersConfig.getNodeAddresses());
    } else if (masterSlaveServersConfig != null) {
        String master = masterSlaveServersConfig.getMasterAddress();
        Set<String> slave = masterSlaveServersConfig.getSlaveAddresses();
        List<String> result = new ArrayList(RedissonUtils.removePre(slave));
        result.addAll(RedissonUtils.removePre(master));
        return result;
    }
    return null;
}
Also used : ClusterServersConfig(org.redisson.config.ClusterServersConfig) ArrayList(java.util.ArrayList) SingleServerConfig(org.redisson.config.SingleServerConfig) MasterSlaveServersConfig(org.redisson.config.MasterSlaveServersConfig) ReflectException(com.shulie.instrument.simulator.api.reflect.ReflectException) URI(java.net.URI) ReplicatedServersConfig(org.redisson.config.ReplicatedServersConfig) SentinelServersConfig(org.redisson.config.SentinelServersConfig)

Example 3 with ReplicatedServersConfig

use of org.redisson.config.ReplicatedServersConfig in project LinkAgent by shulieTech.

the class BaseRedissonTimeSeriesMethodInterceptor method getDatabase.

public int getDatabase(Object target, String methodName, Object[] args) {
    Config config = null;
    try {
        config = manager.getDynamicField(target, RedissonConstants.DYNAMIC_FIELD_CONFIG);
    } catch (Throwable e) {
        return 0;
    }
    if (config == null) {
        return 0;
    }
    SentinelServersConfig sentinelServersConfig = getSentinelServersConfig(config);
    if (sentinelServersConfig != null) {
        int database = sentinelServersConfig.getDatabase();
        return database;
    }
    MasterSlaveServersConfig masterSlaveServersConfig = getMasterSlaveServersConfig(config);
    if (masterSlaveServersConfig != null) {
        return masterSlaveServersConfig.getDatabase();
    }
    SingleServerConfig singleServerConfig = getSingleServerConfig(config);
    if (singleServerConfig != null) {
        return singleServerConfig.getDatabase();
    }
    ClusterServersConfig clusterServersConfig = getClusterServersConfig(config);
    if (clusterServersConfig != null) {
        return 0;
    }
    ReplicatedServersConfig replicatedServersConfig = getReplicatedServersConfig(config);
    if (replicatedServersConfig != null) {
        return replicatedServersConfig.getDatabase();
    }
    return 0;
}
Also used : ReplicatedServersConfig(org.redisson.config.ReplicatedServersConfig) SingleServerConfig(org.redisson.config.SingleServerConfig) ClusterServersConfig(org.redisson.config.ClusterServersConfig) Config(org.redisson.config.Config) ReplicatedServersConfig(org.redisson.config.ReplicatedServersConfig) SentinelServersConfig(org.redisson.config.SentinelServersConfig) MasterSlaveServersConfig(org.redisson.config.MasterSlaveServersConfig) ClusterServersConfig(org.redisson.config.ClusterServersConfig) SentinelServersConfig(org.redisson.config.SentinelServersConfig) SingleServerConfig(org.redisson.config.SingleServerConfig) MasterSlaveServersConfig(org.redisson.config.MasterSlaveServersConfig)

Example 4 with ReplicatedServersConfig

use of org.redisson.config.ReplicatedServersConfig in project LinkAgent by shulieTech.

the class BaseRedissonTimeSeriesMethodInterceptor method getHost.

public String getHost(Object target, String methodName, Object[] args) {
    Config config = manager.getDynamicField(target, RedissonConstants.DYNAMIC_FIELD_CONFIG);
    if (config == null) {
        return null;
    }
    SentinelServersConfig sentinelServersConfig = getSentinelServersConfig(config);
    if (sentinelServersConfig != null) {
        List list = sentinelServersConfig.getSentinelAddresses();
        if (list != null && !list.isEmpty()) {
            StringBuilder builder = new StringBuilder();
            for (Object obj : list) {
                if (obj instanceof String) {
                    String str = (String) obj;
                    if (StringUtils.isBlank(str)) {
                        continue;
                    }
                    if (StringUtils.indexOf(str, ":") != -1) {
                        String[] arr = StringUtils.split(str, ':');
                        builder.append(arr[1]).append(',');
                    }
                } else if (obj instanceof URI) {
                    builder.append(((URI) obj).getHost()).append(",");
                }
            }
            if (builder.length() > 0) {
                builder.deleteCharAt(builder.length() - 1);
            }
            if (builder.length() > 0) {
                return builder.toString();
            } else {
                return "6379";
            }
        }
    }
    MasterSlaveServersConfig masterSlaveServersConfig = getMasterSlaveServersConfig(config);
    if (masterSlaveServersConfig != null) {
        Object masterAddress = masterSlaveServersConfig.getMasterAddress();
        StringBuilder builder = new StringBuilder();
        if (String.class.isAssignableFrom(masterAddress.getClass())) {
            if (StringUtils.isNotBlank((String) masterAddress)) {
                if (StringUtils.indexOf((String) masterAddress, ":") != -1) {
                    String[] arr = StringUtils.split((String) masterAddress, ':');
                    builder.append(arr[0]).append(',');
                }
            }
        } else if (URI.class.isAssignableFrom(masterAddress.getClass())) {
            builder.append(((URI) masterAddress).getHost()).append(',');
        }
        Set set = masterSlaveServersConfig.getSlaveAddresses();
        if (set != null && !set.isEmpty()) {
            for (Object obj : set) {
                if (obj instanceof String) {
                    String str = (String) obj;
                    if (StringUtils.isBlank(str)) {
                        continue;
                    }
                    if (StringUtils.indexOf(str, ":") != -1) {
                        String[] arr = StringUtils.split(str, ':');
                        builder.append(arr[0]).append(',');
                    }
                } else if (URI.class.isAssignableFrom(obj.getClass())) {
                    builder.append(((URI) obj).getHost()).append(",");
                }
            }
        }
        if (builder.length() > 0) {
            builder.deleteCharAt(builder.length() - 1);
        }
        if (builder.length() > 0) {
            return builder.toString();
        } else {
            return "6379";
        }
    }
    SingleServerConfig singleServerConfig = getSingleServerConfig(config);
    if (singleServerConfig != null) {
        String address = getAddress(singleServerConfig);
        if (StringUtils.isNotBlank(address)) {
            if (StringUtils.indexOf(address, ":") == -1) {
                return "6379";
            } else {
                String[] arr = StringUtils.split(address, ':');
                return StringUtils.trim(arr[1]);
            }
        }
    }
    ClusterServersConfig clusterServersConfig = getClusterServersConfig(config);
    if (clusterServersConfig != null) {
        List list = clusterServersConfig.getNodeAddresses();
        if (list != null && !list.isEmpty()) {
            StringBuilder builder = new StringBuilder();
            for (Object obj : list) {
                String str = obj == null ? null : obj.toString();
                if (StringUtils.isBlank(str)) {
                    continue;
                }
                if (StringUtils.indexOf(str, ":") != -1) {
                    String[] arr = StringUtils.split(str, ':');
                    builder.append(arr[0]).append(',');
                }
            }
            if (builder.length() > 0) {
                builder.deleteCharAt(builder.length() - 1);
            }
            if (builder.length() > 0) {
                return builder.toString();
            } else {
                return "6379";
            }
        }
    }
    ReplicatedServersConfig replicatedServersConfig = getReplicatedServersConfig(config);
    if (replicatedServersConfig != null) {
        List list = replicatedServersConfig.getNodeAddresses();
        StringBuilder builder = new StringBuilder();
        for (Object obj : list) {
            String str = obj == null ? null : obj.toString();
            if (StringUtils.isBlank(str)) {
                continue;
            }
            if (StringUtils.indexOf(str, ":") != -1) {
                String[] arr = StringUtils.split(str, ':');
                builder.append(arr[0]).append(',');
            }
        }
        if (builder.length() > 0) {
            builder.deleteCharAt(builder.length() - 1);
        }
        if (builder.length() > 0) {
            return builder.toString();
        } else {
            return "6379";
        }
    }
    return null;
}
Also used : Set(java.util.Set) SingleServerConfig(org.redisson.config.SingleServerConfig) ClusterServersConfig(org.redisson.config.ClusterServersConfig) Config(org.redisson.config.Config) ReplicatedServersConfig(org.redisson.config.ReplicatedServersConfig) SentinelServersConfig(org.redisson.config.SentinelServersConfig) MasterSlaveServersConfig(org.redisson.config.MasterSlaveServersConfig) ClusterServersConfig(org.redisson.config.ClusterServersConfig) SingleServerConfig(org.redisson.config.SingleServerConfig) MasterSlaveServersConfig(org.redisson.config.MasterSlaveServersConfig) URI(java.net.URI) ReplicatedServersConfig(org.redisson.config.ReplicatedServersConfig) SentinelServersConfig(org.redisson.config.SentinelServersConfig) List(java.util.List)

Example 5 with ReplicatedServersConfig

use of org.redisson.config.ReplicatedServersConfig in project force-oneself by Force-oneself.

the class RedissonConfig method useReplicatedServers.

@Bean
@ConditionalOnMissingBean(Config.class)
@ConditionalOnProperty(prefix = RedissonConstant.PROPERTIES_PREFIX, name = "enable", havingValue = "replicated")
public Config useReplicatedServers(RedissonProperties properties) {
    Config config = new Config();
    Objects.requireNonNull(properties.getCluster(), "请配置replicated");
    ReplicatedServersConfig replicated = properties.getReplicated();
    config.useReplicatedServers().setDatabase(replicated.getDatabase()).setPassword(replicated.getPassword()).setScanInterval(replicated.getScanInterval()).getNodeAddresses().addAll(replicated.getNodeAddresses());
    return config;
}
Also used : ReplicatedServersConfig(org.redisson.config.ReplicatedServersConfig) ClusterServersConfig(org.redisson.config.ClusterServersConfig) ReplicatedServersConfig(org.redisson.config.ReplicatedServersConfig) Config(org.redisson.config.Config) SentinelServersConfig(org.redisson.config.SentinelServersConfig) MasterSlaveServersConfig(org.redisson.config.MasterSlaveServersConfig) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean) ConditionalOnProperty(org.springframework.boot.autoconfigure.condition.ConditionalOnProperty)

Aggregations

ClusterServersConfig (org.redisson.config.ClusterServersConfig)9 MasterSlaveServersConfig (org.redisson.config.MasterSlaveServersConfig)9 ReplicatedServersConfig (org.redisson.config.ReplicatedServersConfig)9 SentinelServersConfig (org.redisson.config.SentinelServersConfig)9 SingleServerConfig (org.redisson.config.SingleServerConfig)8 Config (org.redisson.config.Config)6 List (java.util.List)4 Set (java.util.Set)4 URI (java.net.URI)3 ArrayList (java.util.ArrayList)2 Attachment (com.pamirs.attach.plugin.dynamic.Attachment)1 AbstractTemplate (com.pamirs.attach.plugin.dynamic.template.AbstractTemplate)1 RedisTemplate (com.pamirs.attach.plugin.dynamic.template.RedisTemplate)1 RedissionSentinelTemplate (com.pamirs.attach.plugin.dynamic.template.RedisTemplate.RedissionSentinelTemplate)1 RedissionSingleTemplate (com.pamirs.attach.plugin.dynamic.template.RedisTemplate.RedissionSingleTemplate)1 RedissonMasterSlaveTemplate (com.pamirs.attach.plugin.dynamic.template.RedisTemplate.RedissonMasterSlaveTemplate)1 RedissonReplicatedTemplate (com.pamirs.attach.plugin.dynamic.template.RedisTemplate.RedissonReplicatedTemplate)1 ShadowRedisConfig (com.pamirs.pradar.internal.config.ShadowRedisConfig)1 Reflect (com.shulie.instrument.simulator.api.reflect.Reflect)1 ReflectException (com.shulie.instrument.simulator.api.reflect.ReflectException)1