Java Code Examples for org.redisson.Redisson#createRx()

The following examples show how to use org.redisson.Redisson#createRx() . 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: RedissonBatchRxTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testBatchBigRequest() {
    Config config = BaseTest.createConfig();
    config.useSingleServer().setTimeout(15000);
    RedissonRxClient redisson = Redisson.createRx(config);

    RBatchRx batch = redisson.createBatch(batchOptions);
    for (int i = 0; i < 210; i++) {
        batch.getMap("test").fastPut("1", "2");
        batch.getMap("test").fastPut("2", "3");
        batch.getMap("test").put("2", "5");
        batch.getAtomicLong("counter").incrementAndGet();
        batch.getAtomicLong("counter").incrementAndGet();
    }
    BatchResult<?> res = sync(batch.execute());
    Assert.assertEquals(210*5, res.getResponses().size());
    
    redisson.shutdown();
}
 
Example 2
Source File: MainModule.java    From kyoko with MIT License 5 votes vote down vote up
@Singleton
@Provides
RedissonRxClient redisson(Vertx vertx) {
    try {
        var redisConfig = Settings.instance().configureRedis();
        redisConfig.setEventLoopGroup(vertx.nettyEventLoopGroup());
        return Redisson.createRx(redisConfig);
    } catch (Exception e) {
        logger.error("Cannot create Redis client!", e);
        return null;
    }
}
 
Example 3
Source File: RedissonBatchRxTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testConnectionLeakAfterError() throws InterruptedException {
    Config config = BaseTest.createConfig();
    config.useSingleServer()
            .setRetryInterval(100)
            .setTimeout(200)
            .setConnectionMinimumIdleSize(1).setConnectionPoolSize(1);

    RedissonRxClient redisson = Redisson.createRx(config);
    
    BatchOptions batchOptions = BatchOptions.defaults().executionMode(ExecutionMode.REDIS_WRITE_ATOMIC);
    RBatchRx batch = redisson.createBatch(batchOptions);
    for (int i = 0; i < 25000; i++) {
        batch.getBucket("test").set(123);
    }
    
    try {
        sync(batch.execute());
        Assert.fail();
    } catch (Exception e) {
        // skip
    }
    
    sync(redisson.getBucket("test3").set(4));
    assertThat(sync(redisson.getBucket("test3").get())).isEqualTo(4);
    
    batch = redisson.createBatch(batchOptions);
    batch.getBucket("test1").set(1);
    batch.getBucket("test2").set(2);
    sync(batch.execute());
    
    assertThat(sync(redisson.getBucket("test1").get())).isEqualTo(1);
    assertThat(sync(redisson.getBucket("test2").get())).isEqualTo(2);
    
    redisson.shutdown();
}
 
Example 4
Source File: RedissonBatchRxTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testSyncSlaves() 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);
    ClusterProcesses process = clusterRunner.run();
    
    Config config = new Config();
    config.useClusterServers()
    .setTimeout(1000000)
    .setRetryInterval(1000000)
    .addNodeAddress(process.getNodes().stream().findAny().get().getRedisServerAddressAndPort());
    RedissonRxClient redisson = Redisson.createRx(config);
    
    batchOptions
            .syncSlaves(1, 1, TimeUnit.SECONDS);
    
    RBatchRx batch = redisson.createBatch(batchOptions);
    for (int i = 0; i < 100; i++) {
        RMapRx<String, String> map = batch.getMap("test");
        map.put("" + i, "" + i);
    }

    BatchResult<?> result = sync(batch.execute());
    assertThat(result.getResponses()).hasSize(100);
    assertThat(result.getSyncedSlaves()).isEqualTo(1);
    
    process.shutdown();
    redisson.shutdown();
}
 
Example 5
Source File: RedissonBatchRxTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testWriteTimeout() throws InterruptedException {
    Config config = BaseTest.createConfig();
    config.useSingleServer().setRetryInterval(700).setTimeout(1500);
    RedissonRxClient redisson = Redisson.createRx(config);

    RBatchRx batch = redisson.createBatch(batchOptions);
    RMapCacheRx<String, String> map = batch.getMapCache("test");
    int total = 10000;
    for (int i = 0; i < total; i++) {
        map.put("" + i, "" + i, 5, TimeUnit.MINUTES);
        if (batchOptions.getExecutionMode() == ExecutionMode.REDIS_WRITE_ATOMIC) {
            if (i % 100 == 0) {
                Thread.sleep(10);
            }
        }
    }
    
    long s = System.currentTimeMillis();
    sync(batch.execute());
    long executionTime = System.currentTimeMillis() - s;
    if (batchOptions.getExecutionMode() == ExecutionMode.IN_MEMORY) {
        assertThat(executionTime).isLessThan(1000);
    } else {
        assertThat(executionTime).isLessThan(300);
    }
    assertThat(sync(redisson.getMapCache("test").size())).isEqualTo(total);
    redisson.shutdown();
}
 
Example 6
Source File: RedissonFactory.java    From kyoko with MIT License 4 votes vote down vote up
@Singleton
RedissonRxClient getRxClient() throws URISyntaxException {
    var config = Settings.instance().configureRedis();
    return Redisson.createRx(config);
}
 
Example 7
Source File: BaseRxTest.java    From redisson with Apache License 2.0 4 votes vote down vote up
public static RedissonRxClient createInstance() {
    Config config = BaseTest.createConfig();
    return Redisson.createRx(config);
}