Search in sources :

Example 1 with LettuceClusterConnectSourceConfig

use of com.lcache.extend.handle.redis.lettuce.config.LettuceClusterConnectSourceConfig in project lcache by long172066912.

the class RedissonClientManager method getLettuceRedissonConfig.

/**
 * Lettuce配置转Redisson配置
 *
 * @param cacheConfigModel
 * @param cacheConfig
 * @return
 */
private static Config getLettuceRedissonConfig(CacheConfigModel cacheConfigModel, BaseCacheConfig cacheConfig) {
    Config config = new Config();
    switch(cacheConfigModel.getConnectTypeEnum()) {
        case SIMPLE:
            LettuceConnectSourceConfig simpleConfig = (LettuceConnectSourceConfig) cacheConfig;
            config.useSingleServer().setAddress("redis://" + simpleConfig.getHost() + ":" + simpleConfig.getPort()).setPassword(StringUtils.isNotBlank(simpleConfig.getPwd()) ? simpleConfig.getPwd() : null);
            break;
        case POOL:
            LettuceConnectSourceConfig poolConfig = (LettuceConnectSourceConfig) cacheConfig;
            config.useSingleServer().setAddress("redis://" + poolConfig.getHost() + ":" + poolConfig.getPort()).setPassword(StringUtils.isNotBlank(poolConfig.getPwd()) ? poolConfig.getPwd() : null);
            break;
        case SHARDED:
            return null;
        case CLUSTER:
            LettuceClusterConnectSourceConfig clusterConfig = (LettuceClusterConnectSourceConfig) cacheConfig;
            String pwd = "";
            for (LettuceConnectSourceConfig hostAndPort : clusterConfig.getNodes()) {
                config.useClusterServers().addNodeAddress("redis://" + hostAndPort.getHost() + ":" + hostAndPort.getPort());
                pwd = hostAndPort.getPwd();
            }
            config.useClusterServers().setScanInterval(2000).setPassword(StringUtils.isNotBlank(pwd) ? pwd : null);
            break;
        case CLUSTER_POOL:
            LettuceClusterConnectSourceConfig clusterPoolConfig = (LettuceClusterConnectSourceConfig) cacheConfig;
            String pwd1 = "";
            for (LettuceConnectSourceConfig hostAndPort : clusterPoolConfig.getNodes()) {
                config.useClusterServers().addNodeAddress("redis://" + hostAndPort.getHost() + ":" + hostAndPort.getPort());
                pwd1 = hostAndPort.getPwd();
            }
            config.useClusterServers().setScanInterval(2000).setPassword(StringUtils.isNotBlank(pwd1) ? pwd1 : null);
            break;
        default:
            return null;
    }
    return config;
}
Also used : BaseCacheConfig(com.lcache.config.BaseCacheConfig) JedisClusterConnectSourceConfig(com.lcache.extend.handle.redis.jedis.config.JedisClusterConnectSourceConfig) LettuceConnectSourceConfig(com.lcache.extend.handle.redis.lettuce.config.LettuceConnectSourceConfig) Config(org.redisson.config.Config) JedisConnectSourceConfig(com.lcache.extend.handle.redis.jedis.config.JedisConnectSourceConfig) LettuceClusterConnectSourceConfig(com.lcache.extend.handle.redis.lettuce.config.LettuceClusterConnectSourceConfig) LettuceConnectSourceConfig(com.lcache.extend.handle.redis.lettuce.config.LettuceConnectSourceConfig) LettuceClusterConnectSourceConfig(com.lcache.extend.handle.redis.lettuce.config.LettuceClusterConnectSourceConfig)

Aggregations

BaseCacheConfig (com.lcache.config.BaseCacheConfig)1 JedisClusterConnectSourceConfig (com.lcache.extend.handle.redis.jedis.config.JedisClusterConnectSourceConfig)1 JedisConnectSourceConfig (com.lcache.extend.handle.redis.jedis.config.JedisConnectSourceConfig)1 LettuceClusterConnectSourceConfig (com.lcache.extend.handle.redis.lettuce.config.LettuceClusterConnectSourceConfig)1 LettuceConnectSourceConfig (com.lcache.extend.handle.redis.lettuce.config.LettuceConnectSourceConfig)1 Config (org.redisson.config.Config)1