Java Code Examples for org.redisson.config.Config#fromYAML()

The following examples show how to use org.redisson.config.Config#fromYAML() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RedissonRegionFactory.java    From redisson with Apache License 2.0 6 votes vote down vote up
private Config loadConfig(ClassLoader classLoader, String fileName) {
    InputStream is = classLoader.getResourceAsStream(fileName);
    if (is != null) {
        try {
            return Config.fromJSON(is);
        } catch (IOException e) {
            try {
                is = classLoader.getResourceAsStream(fileName);
                return Config.fromYAML(is);
            } catch (IOException e1) {
                throw new CacheException("Can't parse yaml config", e1);
            }
        }
    }
    return null;
}
 
Example 2
Source File: RedissonRegionFactory.java    From redisson with Apache License 2.0 6 votes vote down vote up
private Config loadConfig(ClassLoader classLoader, String fileName) {
    InputStream is = classLoader.getResourceAsStream(fileName);
    if (is != null) {
        try {
            return Config.fromJSON(is);
        } catch (IOException e) {
            try {
                is = classLoader.getResourceAsStream(fileName);
                return Config.fromYAML(is);
            } catch (IOException e1) {
                throw new CacheException("Can't parse yaml config", e1);
            }
        }
    }
    return null;
}
 
Example 3
Source File: RedissonRegionFactory.java    From redisson with Apache License 2.0 6 votes vote down vote up
private Config loadConfig(ClassLoader classLoader, String fileName) {
    InputStream is = classLoader.getResourceAsStream(fileName);
    if (is != null) {
        try {
            return Config.fromJSON(is);
        } catch (IOException e) {
            try {
                is = classLoader.getResourceAsStream(fileName);
                return Config.fromYAML(is);
            } catch (IOException e1) {
                throw new CacheException("Can't parse yaml config", e1);
            }
        }
    }
    return null;
}
 
Example 4
Source File: RedissonRegionFactory.java    From redisson with Apache License 2.0 6 votes vote down vote up
private Config loadConfig(ClassLoader classLoader, String fileName) {
    InputStream is = classLoader.getResourceAsStream(fileName);
    if (is != null) {
        try {
            return Config.fromJSON(is);
        } catch (IOException e) {
            try {
                is = classLoader.getResourceAsStream(fileName);
                return Config.fromYAML(is);
            } catch (IOException e1) {
                throw new CacheException("Can't parse yaml config", e1);
            }
        }
    }
    return null;
}
 
Example 5
Source File: RedissonRegionFactory.java    From redisson with Apache License 2.0 5 votes vote down vote up
private Config loadConfig(String configPath) {
    try {
        return Config.fromJSON(new File(configPath));
    } catch (IOException e) {
        // trying next format
        try {
            return Config.fromYAML(new File(configPath));
        } catch (IOException e1) {
            throw new CacheException("Can't parse default yaml config", e1);
        }
    }
}
 
Example 6
Source File: RedissonConfigurationIntegrationTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenYAMLFileConfig_thenRedissonConnectToRedis() throws IOException {
    
    File configFile = new File(getClass().getClassLoader().getResource("singleNodeConfig.yaml").getFile());
    String configContent = Files.toString(configFile, Charset.defaultCharset()).replace("6379", String.valueOf(port));
    
    Config config = Config.fromYAML(configContent);
    client = Redisson.create(config);

    assert(client != null && client.getKeys().count() >= 0);
}
 
Example 7
Source File: RedissonRegionFactory.java    From redisson with Apache License 2.0 5 votes vote down vote up
private Config loadConfig(String configPath) {
    try {
        return Config.fromJSON(new File(configPath));
    } catch (IOException e) {
        // trying next format
        try {
            return Config.fromYAML(new File(configPath));
        } catch (IOException e1) {
            throw new CacheException("Can't parse default yaml config", e1);
        }
    }
}
 
Example 8
Source File: RedissonRegionFactory.java    From redisson with Apache License 2.0 5 votes vote down vote up
private Config loadConfig(String configPath) {
    try {
        return Config.fromJSON(new File(configPath));
    } catch (IOException e) {
        // trying next format
        try {
            return Config.fromYAML(new File(configPath));
        } catch (IOException e1) {
            throw new CacheException("Can't parse default yaml config", e1);
        }
    }
}
 
Example 9
Source File: RedissonRegionFactory.java    From redisson with Apache License 2.0 5 votes vote down vote up
private Config loadConfig(String configPath) {
    try {
        return Config.fromJSON(new File(configPath));
    } catch (IOException e) {
        // trying next format
        try {
            return Config.fromYAML(new File(configPath));
        } catch (IOException e1) {
            throw new CacheException("Can't parse default yaml config", e1);
        }
    }
}
 
Example 10
Source File: RedisInitializer.java    From tio-starters with MIT License 5 votes vote down vote up
private Config getConfigByFile() {
    try {
        if (redisConfig.isJSONConfig()) {
            return Config.fromJSON(getFileUri(redisConfig.getConfigPath()));
        } else if (redisConfig.isYAMLConfig()) {
            return Config.fromYAML(getFileUri(redisConfig.getConfigPath()));
        }
    } catch (IOException e) {
        logger.error("init with file config error", e);
    }
    return null;
}
 
Example 11
Source File: RedissonTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testMasterSlaveConfigYAML() throws IOException {
    Config c2 = new Config();
    c2.useMasterSlaveServers().setMasterAddress("redis://123.1.1.1:1231").addSlaveAddress("redis://82.12.47.12:1028", "redis://82.12.47.14:1028");
    String t = c2.toYAML();
    Config c = Config.fromYAML(t);
    assertThat(c.toYAML()).isEqualTo(t);
}
 
Example 12
Source File: RedissonTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testSentinelYAML() throws IOException {
    Config c2 = new Config();
    c2.useSentinelServers().addSentinelAddress("redis://123.1.1.1:1231").setMasterName("mymaster");
    String t = c2.toYAML();
    System.out.println(t);
    Config c = Config.fromYAML(t);
    assertThat(c.toYAML()).isEqualTo(t);
}
 
Example 13
Source File: RedissonTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testSingleConfigYAML() throws IOException {
    RedissonClient r = BaseTest.createInstance();
    String t = r.getConfig().toYAML();
    Config c = Config.fromYAML(t);
    assertThat(c.toYAML()).isEqualTo(t);
}
 
Example 14
Source File: JCachingProvider.java    From redisson with Apache License 2.0 5 votes vote down vote up
private Config loadConfig(URI uri) {
    Config config = null;
    try {
        URL jsonUrl = null;
        if (DEFAULT_URI_PATH.equals(uri.getPath())) {
            jsonUrl = JCachingProvider.class.getResource("/redisson-jcache.json");
        } else {
            jsonUrl = uri.toURL();
        }
        if (jsonUrl == null) {
            throw new IOException();
        }
        config = Config.fromJSON(jsonUrl);
    } catch (IOException e) {
        try {
            URL yamlUrl = null;
            if (DEFAULT_URI_PATH.equals(uri.getPath())) {
                yamlUrl = JCachingProvider.class.getResource("/redisson-jcache.yaml");
            } else {
                yamlUrl = uri.toURL();
            }
            if (yamlUrl != null) {
                config = Config.fromYAML(yamlUrl);
            }
        } catch (IOException e2) {
            // skip
        }
    }
    return config;
}
 
Example 15
Source File: RedissonCache.java    From redisson with Apache License 2.0 5 votes vote down vote up
public void setRedissonConfig(String config) {
    Config cfg;
    try {
        InputStream is = getClass().getResourceAsStream(config);
        cfg = Config.fromYAML(is);
    } catch (IOException e) {
        throw new IllegalArgumentException("Can't parse config", e);
    }

    RedissonClient redisson = Redisson.create(cfg);
    mapCache = getMapCache(id, redisson);
    if (maxSize > 0) {
        mapCache.setMaxSize(maxSize);
    }
}
 
Example 16
Source File: RedisInitializer.java    From t-io with Apache License 2.0 5 votes vote down vote up
private Config getConfigByFile() {
    try {
        if (redisConfig.isJSONConfig()) {
            return Config.fromJSON(getFileUri(redisConfig.getConfigPath()));
        } else if (redisConfig.isYAMLConfig()) {
            return Config.fromYAML(getFileUri(redisConfig.getConfigPath()));
        }
    } catch (IOException e) {
        logger.error("init with file config error", e);
    }
    return null;
}
 
Example 17
Source File: RedissonConfig.java    From hdw-dubbo with Apache License 2.0 4 votes vote down vote up
@Bean(destroyMethod = "shutdown")
public RedissonClient RedissonClient() throws IOException {
    Config config = Config.fromYAML(new ClassPathResource("redisson-single.yml").getInputStream());
    RedissonClient redisson = Redisson.create(config);
    return redisson;
}