org.redisson.config.Config Java Examples

The following examples show how to use org.redisson.config.Config. 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: RedissonClusterConnectionTest.java    From redisson with Apache License 2.0 7 votes vote down vote up
@BeforeClass
public static void before() throws FailedToStartRedisException, IOException, InterruptedException {
    RedisRunner master1 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner master2 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner master3 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner slave1 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner slave2 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner slave3 = new RedisRunner().randomPort().randomDir().nosave();

    
    ClusterRunner clusterRunner = new ClusterRunner()
            .addNode(master1, slave1)
            .addNode(master2, slave2)
            .addNode(master3, slave3);
    process = clusterRunner.run();
    
    Config config = new Config();
    config.useClusterServers()
    .setSubscriptionMode(SubscriptionMode.SLAVE)
    .setLoadBalancer(new RandomLoadBalancer())
    .addNodeAddress(process.getNodes().stream().findAny().get().getRedisServerAddressAndPort());
    
    redisson = Redisson.create(config);
    connection = new RedissonClusterConnection(redisson);
}
 
Example #2
Source File: RedisLockTest.java    From conductor with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUp() throws Exception {
    String testServerAddress = "redis://127.0.0.1:6371";
    redisServer = new RedisServer(6371);
    if (redisServer.isActive()) {
        redisServer.stop();
    }
    redisServer.start();

    RedisLockConfiguration redisLockConfiguration = new SystemPropertiesRedisLockConfiguration() {
        @Override
        public String getRedisServerAddress() {
            return testServerAddress;
        }
    };

    Config redissonConfig = new Config();
    redissonConfig.useSingleServer().setAddress(testServerAddress).setTimeout(10000);
    redisLock = new RedisLock((Redisson) Redisson.create(redissonConfig), redisLockConfiguration);

    // Create another instance of redisson for tests.
    config = new Config();
    config.useSingleServer().setAddress(testServerAddress).setTimeout(10000);
    redisson = Redisson.create(config);
}
 
Example #3
Source File: RedissonMapCacheTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testExpirationWithMaxSize() throws InterruptedException {
    Config config = new Config();
    config.useSingleServer().setAddress(RedisRunner.getDefaultRedisServerBindAddressAndPort());
    config.setMaxCleanUpDelay(2);
    config.setMinCleanUpDelay(1);
    RedissonClient redisson = Redisson.create(config);

    RMapCache<String, String> map = redisson.getMapCache("test", StringCodec.INSTANCE);
    assertThat(map.trySetMaxSize(2)).isTrue();

    map.put("1", "1", 3, TimeUnit.SECONDS);
    map.put("2", "2", 0, TimeUnit.SECONDS, 3, TimeUnit.SECONDS);
    map.put("3", "3", 3, TimeUnit.SECONDS);
    map.put("4", "4", 0, TimeUnit.SECONDS, 3, TimeUnit.SECONDS);

    Thread.sleep(5000);

    assertThat(map.size()).isZero();

    assertThat(redisson.getKeys().count()).isEqualTo(2);
    redisson.shutdown();
}
 
Example #4
Source File: DefaultReferenceCodecProvider.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Override
public <T extends Codec, K extends RObject> T getCodec(RObjectField anno, Class<?> cls, Class<K> rObjectClass, String fieldName, Config config) {
    try {
        if (!ClassUtils.getDeclaredField(cls, fieldName).isAnnotationPresent(anno.getClass())) {
            throw new IllegalArgumentException("Annotation RObjectField does not present on field " + fieldName + " of type [" + cls.getCanonicalName() + "]");
        }
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
    if (rObjectClass.isInterface()) {
        throw new IllegalArgumentException("Cannot lookup an interface class of RObject [" + rObjectClass.getCanonicalName() + "]. Concrete class only.");
    }
    
    Class<?> codecClass;
    if (anno.codec() == RObjectField.DEFAULT.class) {
        codecClass = config.getCodec().getClass();
    } else {
        codecClass = anno.codec();
    }
    
    return this.<T>getCodec((Class<T>) codecClass);
}
 
Example #5
Source File: RedissonClusterConnectionTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void before() throws FailedToStartRedisException, IOException, InterruptedException {
    RedisRunner master1 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner master2 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner master3 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner slave1 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner slave2 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner slave3 = new RedisRunner().randomPort().randomDir().nosave();

    
    ClusterRunner clusterRunner = new ClusterRunner()
            .addNode(master1, slave1)
            .addNode(master2, slave2)
            .addNode(master3, slave3);
    process = clusterRunner.run();
    
    Config config = new Config();
    config.useClusterServers()
    .setSubscriptionMode(SubscriptionMode.SLAVE)
    .setLoadBalancer(new RandomLoadBalancer())
    .addNodeAddress(process.getNodes().stream().findAny().get().getRedisServerAddressAndPort());
    
    redisson = Redisson.create(config);
    connection = new RedissonClusterConnection(redisson);
}
 
Example #6
Source File: JCacheTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testAsync() throws Exception {
    RedisProcess runner = new RedisRunner()
            .nosave()
            .randomDir()
            .port(6311)
            .run();
    
    URL configUrl = getClass().getResource("redisson-jcache.json");
    Config cfg = Config.fromJSON(configUrl);
    
    Configuration<String, String> config = RedissonConfiguration.fromConfig(cfg);
    Cache<String, String> cache = Caching.getCachingProvider().getCacheManager()
            .createCache("test", config);

    CacheAsync<String, String> async = cache.unwrap(CacheAsync.class);
    async.putAsync("1", "2").get();
    assertThat(async.getAsync("1").get()).isEqualTo("2");
    
    cache.close();
    runner.stop();
}
 
Example #7
Source File: Settings.java    From kyoko with MIT License 6 votes vote down vote up
@JsonIgnore
public Config configureRedis() throws URISyntaxException {
    var redisConfig = new Config();
    var redis = new URI(Settings.instance().redisUrl());
    if (!redis.getScheme().equals("redis") && !redis.getScheme().equals("rediss")) {
        throw new IllegalArgumentException("Invalid scheme for Redis connection URI!");
    }

    var database = redis.getPath() == null || redis.getPath().isBlank() ? 0
            : Integer.parseUnsignedInt(redis.getPath().substring(1));

    redisConfig.setTransportMode(Epoll.isAvailable() ? TransportMode.EPOLL : TransportMode.NIO);
    redisConfig.setNettyThreads(16);
    redisConfig.useSingleServer()
            .setAddress(redis.getScheme() + "://"
                    + requireNonNullElse(redis.getHost(), "localhost") + ":"
                    + requireNonNullElse(redis.getPort(), 6379))
            .setDatabase(database)
            .setPassword(redis.getUserInfo());

    return redisConfig;
}
 
Example #8
Source File: RedisInitializer.java    From t-io with Apache License 2.0 6 votes vote down vote up
/**
 * @author kuangyoubo
 * @author fanpan26
 * 优先级
 * 通过名字注入 > 配置文件 > 参数配置 > 默认
 */
private void initRedis() {
    if( redisConfig.useInjectRedissonClient() ) {
        logger.info("Get the RedissonClient through injection, Bean name is \"{}\"", redisConfig.getClientBeanName());

        try {
            redissonClient = applicationContext.getBean(redisConfig.getClientBeanName(), RedissonClient.class);
            return;
        } catch (BeansException e) {
            logger.warn("RedissonClient is not found, Recreate RedissonClient on configuration information.");
        }
    }

    /**
     * 优先级
     * 配置文件 > 参数配置 > 默认
     */
    Config config = getConfigByFile();
    if(config == null) {
        config = redisConfig.useConfigParameter() ? redisConfig.getClusterOrSentinelConfig() : getSingleServerConfig();
    }
    redissonClient = Redisson.create(config);
}
 
Example #9
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 #10
Source File: RedisCollector.java    From karaf-decanter with Apache License 2.0 6 votes vote down vote up
@Activate
public void activate(ComponentContext componentContext) {
    config = componentContext.getProperties();

    String address = (config.get("address") != null) ? config.get("address").toString() : ADDRESS_DEFAULT;
    String mode = (config.get("map") != null) ? config.get("map").toString() : MODE_DEFAULT;
    String masterAddress = (config.get("masterAddress") != null) ? config.get("masterAddress").toString() : null;
    String masterName = (config.get("masterName") != null) ? config.get("masterName").toString() : null;
    int scanInterval = (config.get("scanInterval") != null) ? Integer.parseInt(config.get("scanInterval").toString()) : 2000;

    Config redissonConfig = new Config();
    if (mode.equalsIgnoreCase("Single")) {
        redissonConfig.useSingleServer().setAddress(address);
    } else if (mode.equalsIgnoreCase("Master_Slave")) {
        redissonConfig.useMasterSlaveServers().setMasterAddress(masterAddress).addSlaveAddress(address);
    } else if (mode.equalsIgnoreCase("Sentinel")) {
        redissonConfig.useSentinelServers().addSentinelAddress(masterName).addSentinelAddress(address);
    } else if (mode.equalsIgnoreCase("Cluster")) {
        redissonConfig.useClusterServers().setScanInterval(scanInterval).addNodeAddress(address);
    }
    redissonClient = Redisson.create(redissonConfig);
}
 
Example #11
Source File: RedissonTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
public void testLeak() throws InterruptedException {
    Config config = new Config();
    config.useSingleServer()
          .setAddress(RedisRunner.getDefaultRedisServerBindAddressAndPort());

    RedissonClient localRedisson = Redisson.create(config);

    String key = RandomString.make(120);
    for (int i = 0; i < 500; i++) {
        RMapCache<String, String> cache = localRedisson.getMapCache("mycache");
        RLock keyLock = cache.getLock(key);
        keyLock.lockInterruptibly(10, TimeUnit.SECONDS);
        try {
            cache.get(key);
            cache.put(key, RandomString.make(4*1024*1024), 5, TimeUnit.SECONDS);
        } finally {
            if (keyLock != null) {
                keyLock.unlock();
            }
        }
    }
    

}
 
Example #12
Source File: RateLimiterTest.java    From blog with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static void main(String[] args) {
	Config config = new Config();
	config.useSingleServer().setAddress("redis://localhost:6379");
	RedissonClient client = Redisson.create(config);

	RRateLimiter rateLimiter = client.getRateLimiter("rate_limiter");
	rateLimiter.trySetRate(RateType.OVERALL, 1, 5, RateIntervalUnit.SECONDS);

	ExecutorService executorService = Executors.newFixedThreadPool(10);
	for (int i = 0; i < 10; i++) {
		executorService.submit(() -> {
			try {
				rateLimiter.acquire();
				System.out.println("时间:" + System.currentTimeMillis() + ",线程" + Thread.currentThread().getId()
						+ "进入数据区:" + System.currentTimeMillis());
			} catch (Exception e) {
				e.printStackTrace();
			}
		});
	}
}
 
Example #13
Source File: ExecutorServiceExamples.java    From redisson-examples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    Config config = new Config();
    config.useClusterServers()
        .addNodeAddress("127.0.0.1:7001", "127.0.0.1:7002", "127.0.0.1:7003");
    
    RedissonClient redisson = Redisson.create(config);

    RedissonNodeConfig nodeConfig = new RedissonNodeConfig(config);
    nodeConfig.setExecutorServiceWorkers(Collections.singletonMap("myExecutor", 1));
    RedissonNode node = RedissonNode.create(nodeConfig);
    node.start();

    RExecutorService e = redisson.getExecutorService("myExecutor");
    e.execute(new RunnableTask());
    e.submit(new CallableTask());
    
    e.shutdown();
    node.shutdown();
}
 
Example #14
Source File: RedissonClientFactory.java    From extract with MIT License 6 votes vote down vote up
/**
 * Create a new connection manager for a single server using the supplied address.
 *
 * @return a new connection manager
 */
public RedissonClient create() {
	final String address = null == this.address ? "redis://127.0.0.1:6379" : this.address;
	final int timeout = this.timeout < 0 ? 60 * 1000 : this.timeout;

	// TODO: support all the other types supported by the RedissonClientFactory.
	// TODO: Create a hash of config options so that only one manager is used per unique server. This should
	// improve contention.
	Config config = new Config();
	config.useSingleServer().
			setConnectionPoolSize(1).
			setConnectionMinimumIdleSize(1).
			setAddress(address).
			setTimeout(timeout);
       return Redisson.create(config);
}
 
Example #15
Source File: BaseTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
public static Config createConfig() {
//        String redisAddress = System.getProperty("redisAddress");
//        if (redisAddress == null) {
//            redisAddress = "127.0.0.1:6379";
//        }
        Config config = new Config();
//        config.setCodec(new MsgPackJacksonCodec());
//        config.useSentinelServers().setMasterName("mymaster").addSentinelAddress("127.0.0.1:26379", "127.0.0.1:26389");
//        config.useClusterServers().addNodeAddress("127.0.0.1:7004", "127.0.0.1:7001", "127.0.0.1:7000");
        config.useSingleServer()
                .setAddress(RedisRunner.getDefaultRedisServerBindAddressAndPort());
//        .setPassword("mypass1");
//        config.useMasterSlaveConnection()
//        .setMasterAddress("127.0.0.1:6379")
//        .addSlaveAddress("127.0.0.1:6399")
//        .addSlaveAddress("127.0.0.1:6389");
        return config;
    }
 
Example #16
Source File: RedissonBucketTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testMigrate() throws FailedToStartRedisException, IOException, InterruptedException {
    RedisProcess runner = new RedisRunner()
            .appendonly(true)
            .randomDir()
            .randomPort()
            .run();
    
    RBucket<String> bucket = redisson.getBucket("test");
    bucket.set("someValue");
    
    bucket.migrate(runner.getRedisServerBindAddress(), runner.getRedisServerPort(), 0, 5000);
    
    Config config = new Config();
    config.useSingleServer().setAddress(runner.getRedisServerAddressAndPort());
    RedissonClient r = Redisson.create(config);
    
    RBucket<String> bucket2 = r.getBucket("test");
    assertThat(bucket2.get()).isEqualTo("someValue");
    assertThat(bucket.isExists()).isFalse();
    
    runner.stop();
}
 
Example #17
Source File: BaseTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
public static Config createConfig() {
//        String redisAddress = System.getProperty("redisAddress");
//        if (redisAddress == null) {
//            redisAddress = "127.0.0.1:6379";
//        }
        Config config = new Config();
//        config.setCodec(new MsgPackJacksonCodec());
//        config.useSentinelServers().setMasterName("mymaster").addSentinelAddress("127.0.0.1:26379", "127.0.0.1:26389");
//        config.useClusterServers().addNodeAddress("127.0.0.1:7004", "127.0.0.1:7001", "127.0.0.1:7000");
        config.useSingleServer()
                .setAddress(RedisRunner.getDefaultRedisServerBindAddressAndPort());
//        .setPassword("mypass1");
//        config.useMasterSlaveConnection()
//        .setMasterAddress("127.0.0.1:6379")
//        .addSlaveAddress("127.0.0.1:6399")
//        .addSlaveAddress("127.0.0.1:6389");
        return config;
    }
 
Example #18
Source File: RedissonExecutorServiceTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
public void testTaskFinishing() throws Exception {
    AtomicInteger counter = new AtomicInteger();
    new MockUp<TasksRunnerService>() {
        @Mock
        private void finish(Invocation invocation, String requestId) {
            if (counter.incrementAndGet() > 1) {
                invocation.proceed();
            }
        }
    };
    
    Config config = createConfig();
    RedissonNodeConfig nodeConfig = new RedissonNodeConfig(config);
    nodeConfig.setExecutorServiceWorkers(Collections.singletonMap("test2", 1));
    node.shutdown();
    node = RedissonNode.create(nodeConfig);
    node.start();
    
    RExecutorService executor = redisson.getExecutorService("test2");
    RExecutorFuture<?> f = executor.submit(new FailoverTask("finished"));
    Thread.sleep(2000);
    node.shutdown();

    f.get();
    assertThat(redisson.<Boolean>getBucket("finished").get()).isTrue();
}
 
Example #19
Source File: RedissonBatchTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testSyncSlavesWait() {
    Config config = createConfig();
    config.useSingleServer()
            .setConnectionMinimumIdleSize(1)
            .setConnectionPoolSize(1);

    RedissonClient redisson = Redisson.create(config);

    try {
                batchOptions
                .skipResult()
                .syncSlaves(2, 1, TimeUnit.SECONDS);
        RBatch batch = redisson.createBatch(batchOptions);
        RBucketAsync<Integer> bucket = batch.getBucket("1");
        bucket.setAsync(1);
        batch.execute();
        String[] t = redisson.getKeys().getKeysStreamByPattern("*").toArray(String[]::new);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
 
Example #20
Source File: RedissonClusterConnectionTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void before() throws FailedToStartRedisException, IOException, InterruptedException {
    RedisRunner master1 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner master2 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner master3 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner slave1 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner slave2 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner slave3 = new RedisRunner().randomPort().randomDir().nosave();

    
    ClusterRunner clusterRunner = new ClusterRunner()
            .addNode(master1, slave1)
            .addNode(master2, slave2)
            .addNode(master3, slave3);
    process = clusterRunner.run();
    
    Config config = new Config();
    config.useClusterServers()
    .setSubscriptionMode(SubscriptionMode.SLAVE)
    .setLoadBalancer(new RandomLoadBalancer())
    .addNodeAddress(process.getNodes().stream().findAny().get().getRedisServerAddressAndPort());
    
    redisson = Redisson.create(config);
    connection = new RedissonClusterConnection(redisson);
}
 
Example #21
Source File: RedisRatelimiter.java    From Limiter with Apache License 2.0 5 votes vote down vote up
/**
 * @param limiterName
 * @param config
 */
public RedisRatelimiter(String limiterName, Config config) {
    this.limiterName = limiterName;
    this.ratelimiterRedission = new RateLimiterRedission(config);
    logger.info("RedisRateLimiter named {} start success!", limiterName);

}
 
Example #22
Source File: JCacheTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testRemoveAll() throws Exception {
    RedisProcess runner = new RedisRunner()
            .nosave()
            .randomDir()
            .port(6311)
            .run();
    
    URL configUrl = getClass().getResource("redisson-jcache.json");
    Config cfg = Config.fromJSON(configUrl);
    
    Configuration<String, String> config = RedissonConfiguration.fromConfig(cfg);
    Cache<String, String> cache = Caching.getCachingProvider().getCacheManager()
            .createCache("test", config);
    
    cache.put("1", "2");
    cache.put("3", "4");
    cache.put("4", "4");
    cache.put("5", "5");
    
    Set<? extends String> keys = new HashSet<String>(Arrays.asList("1", "3", "4", "5"));
    cache.removeAll(keys);
    assertThat(cache.containsKey("1")).isFalse();
    assertThat(cache.containsKey("3")).isFalse();
    assertThat(cache.containsKey("4")).isFalse();
    assertThat(cache.containsKey("5")).isFalse();
    
    cache.close();
    runner.stop();
}
 
Example #23
Source File: RedissonListTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testAddListener() throws RedisRunner.FailedToStartRedisException, IOException, InterruptedException {
    RedisRunner.RedisProcess instance = new RedisRunner()
            .nosave()
            .randomPort()
            .randomDir()
            .notifyKeyspaceEvents(
                                RedisRunner.KEYSPACE_EVENTS_OPTIONS.E,
                                RedisRunner.KEYSPACE_EVENTS_OPTIONS.l)
            .run();

    Config config = new Config();
    config.useSingleServer().setAddress(instance.getRedisServerAddressAndPort());
    RedissonClient redisson = Redisson.create(config);

    RList<Integer> al = redisson.getList("name");
    CountDownLatch latch = new CountDownLatch(1);
    al.addListener(new ListAddListener() {
        @Override
        public void onListAdd(String name) {
            latch.countDown();
        }
    });
    al.add(1);

    assertThat(latch.await(1, TimeUnit.SECONDS)).isTrue();

    redisson.shutdown();
    instance.stop();
}
 
Example #24
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 #25
Source File: RedissonCodecTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testSnappyV2() {
    Config config = createConfig();
    config.setCodec(snappyCodecV2);
    RedissonClient redisson = Redisson.create(config);

    test(redisson);
}
 
Example #26
Source File: MasterslaveRedissonConfigStrategyImpl.java    From redis-distributed-lock with Apache License 2.0 5 votes vote down vote up
@Override
public Config createRedissonConfig(RedissonProperties redissonProperties) {
    Config config = new Config();
    try {
        String address = redissonProperties.getAddress();
        String password = redissonProperties.getPassword();
        int database = redissonProperties.getDatabase();
        String[] addrTokens = address.split(",");
        String masterNodeAddr = addrTokens[0];
        /**设置主节点ip*/
        config.useMasterSlaveServers().setMasterAddress(masterNodeAddr);
        if (StringUtils.isNotBlank(password)) {
            config.useMasterSlaveServers().setPassword(password);
        }
        config.useMasterSlaveServers().setDatabase(database);
        /**设置从节点,移除第一个节点,默认第一个为主节点*/
        List<String> slaveList = new ArrayList<>();
        for (String addrToken : addrTokens) {
            slaveList.add(GlobalConstant.REDIS_CONNECTION_PREFIX.getConstant_value() + addrToken);
        }
        slaveList.remove(0);

        config.useMasterSlaveServers().addSlaveAddress((String[]) slaveList.toArray());
        LOGGER.info("初始化[MASTERSLAVE]方式Config,redisAddress:" + address);
    } catch (Exception e) {
        LOGGER.error("MASTERSLAVE Redisson init error", e);
        e.printStackTrace();
    }
    return config;
}
 
Example #27
Source File: RedissonLockProviderIntegrationTest.java    From ShedLock with Apache License 2.0 5 votes vote down vote up
private static RedisConnectionFactory createRedissonConnectionFactory() {
    Config config = new Config();
    config.useSingleServer()
        .setAddress("redis://" + HOST + ":" + PORT);
    RedissonClient redisson = Redisson.create(config);
    return new RedissonConnectionFactory(redisson);
}
 
Example #28
Source File: RedissonCodecTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testFst() {
    Config config = createConfig();
    config.setCodec(fstCodec);
    RedissonClient redisson = Redisson.create(config);

    test(redisson);
}
 
Example #29
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 #30
Source File: RedissonAutoConfiguration.java    From redisson-spring-boot with Apache License 2.0 5 votes vote down vote up
private void configReplicated(Config config) {
    ReplicatedServersConfig properties = redissonProperties.getReplicated();
    config.useReplicatedServers()
            // BaseConfig
            .setPassword(properties.getPassword())
            .setSubscriptionsPerConnection(properties.getSubscriptionsPerConnection())
            .setRetryAttempts(properties.getRetryAttempts())
            .setRetryInterval(properties.getRetryInterval())
            .setTimeout(properties.getTimeout())
            .setClientName(properties.getClientName())
            .setPingTimeout(properties.getPingTimeout())
            .setConnectTimeout(properties.getConnectTimeout())
            .setIdleConnectionTimeout(properties.getIdleConnectionTimeout())
            .setSslEnableEndpointIdentification(properties.isSslEnableEndpointIdentification())
            .setSslProvider(properties.getSslProvider())
            .setSslTruststore(properties.getSslTrustStore())
            .setSslTruststorePassword(properties.getSslKeystorePassword())
            .setSslKeystore(properties.getSslKeystore())
            .setSslKeystorePassword(properties.getSslKeystorePassword())
            .setPingConnectionInterval(properties.getPingConnectionInterval())
            .setKeepAlive(properties.isKeepAlive())
            .setTcpNoDelay(properties.isTcpNoDelay())
            // BaseMasterSlaveServersConfig
            .setLoadBalancer(properties.getLoadBalancer().getInstance())
            .setMasterConnectionMinimumIdleSize(properties.getMasterConnectionMinimumIdleSize())
            .setMasterConnectionPoolSize(properties.getMasterConnectionPoolSize())
            .setSlaveConnectionMinimumIdleSize(properties.getSlaveConnectionMinimumIdleSize())
            .setSlaveConnectionPoolSize(properties.getSlaveConnectionPoolSize())
            .setSubscriptionConnectionMinimumIdleSize(properties.getSubscriptionConnectionMinimumIdleSize())
            .setSubscriptionConnectionPoolSize(properties.getSubscriptionConnectionPoolSize())
            .setFailedSlaveCheckInterval(properties.getFailedSlaveCheckInterval())
            .setFailedSlaveReconnectionInterval(properties.getFailedSlaveReconnectionInterval())
            .setReadMode(properties.getReadMode())
            .setSubscriptionMode(properties.getSubscriptionMode())
            .setDnsMonitoringInterval(properties.getDnsMonitoringInterval())
            // ReplicatedServersConfig
            .addNodeAddress(properties.getNodeAddresses())
            .setScanInterval(properties.getScanInterval())
            .setDatabase(properties.getDatabase());
}