Java Code Examples for org.redisson.client.RedisConnection#sync()

The following examples show how to use org.redisson.client.RedisConnection#sync() . 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: SpringNamespaceWikiTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testRedisClient() throws Exception {
    RedisRunner.RedisProcess run = new RedisRunner()
            .requirepass("do_not_use_if_it_is_not_set")
            .nosave()
            .randomDir()
            .run();
    try {
        ClassPathXmlApplicationContext context
                = new ClassPathXmlApplicationContext("classpath:org/redisson/spring/support/namespace_wiki_redis_client.xml");
        RedisClient redisClient = context.getBean(RedisClient.class);
        RedisConnection connection = redisClient.connect();
        Map<String, String> info = connection.sync(RedisCommands.INFO_ALL);
        assertThat(info, notNullValue());
        assertThat(info, not(info.isEmpty()));
        ((ConfigurableApplicationContext) context).close();
    } finally {
        run.stop();
    }
}
 
Example 2
Source File: RedisClientTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void test() throws InterruptedException {
    final RedisConnection conn = redisClient.connect();

    conn.sync(StringCodec.INSTANCE, RedisCommands.SET, "test", 0);
    ExecutorService pool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2);
    for (int i = 0; i < 100000; i++) {
        pool.execute(() -> {
            conn.async(StringCodec.INSTANCE, RedisCommands.INCR, "test");
        });
    }

    pool.shutdown();

    assertThat(pool.awaitTermination(1, TimeUnit.HOURS)).isTrue();

    assertThat((Long) conn.sync(LongCodec.INSTANCE, RedisCommands.GET, "test")).isEqualTo(100000);

    conn.sync(RedisCommands.FLUSHDB);
}
 
Example 3
Source File: RedisClientTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testPipeline() throws InterruptedException, ExecutionException {
    RedisConnection conn = redisClient.connect();

    conn.sync(StringCodec.INSTANCE, RedisCommands.SET, "test", 0);

    List<CommandData<?, ?>> commands = new ArrayList<CommandData<?, ?>>();
    CommandData<String, String> cmd1 = conn.create(null, RedisCommands.PING);
    commands.add(cmd1);
    CommandData<Long, Long> cmd2 = conn.create(null, RedisCommands.INCR, "test");
    commands.add(cmd2);
    CommandData<Long, Long> cmd3 = conn.create(null, RedisCommands.INCR, "test");
    commands.add(cmd3);
    CommandData<String, String> cmd4 = conn.create(null, RedisCommands.PING);
    commands.add(cmd4);

    RPromise<Void> p = new RedissonPromise<Void>();
    conn.send(new CommandsData(p, commands, false, false));

    assertThat(cmd1.getPromise().get()).isEqualTo("PONG");
    assertThat(cmd2.getPromise().get()).isEqualTo(1);
    assertThat(cmd3.getPromise().get()).isEqualTo(2);
    assertThat(cmd4.getPromise().get()).isEqualTo("PONG");

    conn.sync(RedisCommands.FLUSHDB);
}
 
Example 4
Source File: RedisClientTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testPipelineBigResponse() throws InterruptedException, ExecutionException {
    RedisConnection conn = redisClient.connect();

    List<CommandData<?, ?>> commands = new ArrayList<CommandData<?, ?>>();
    for (int i = 0; i < 1000; i++) {
        CommandData<String, String> cmd1 = conn.create(null, RedisCommands.PING);
        commands.add(cmd1);
    }

    RPromise<Void> p = new RedissonPromise<Void>();
    conn.send(new CommandsData(p, commands, false, false));

    for (CommandData<?, ?> commandData : commands) {
        commandData.getPromise().get();
    }

    conn.sync(RedisCommands.FLUSHDB);
}
 
Example 5
Source File: RedisRunner.java    From redisson with Apache License 2.0 5 votes vote down vote up
public RedisVersion getRedisVersion() {
    if (redisVersion == null) {
        RedisConnection c = createRedisClientInstance().connect();
        Map<String, String> serverMap = c.sync(RedisCommands.INFO_SERVER);
        redisVersion = new RedisVersion(serverMap.get("redis_version"));
        c.closeAsync();
    }
    return redisVersion;
}
 
Example 6
Source File: RedisRunner.java    From redisson with Apache License 2.0 5 votes vote down vote up
public RedisVersion getRedisVersion() {
    if (redisVersion == null) {
        RedisConnection c = createRedisClientInstance().connect();
        Map<String, String> serverMap = c.sync(RedisCommands.INFO_SERVER);
        redisVersion = new RedisVersion(serverMap.get("redis_version"));
        c.closeAsync();
    }
    return redisVersion;
}
 
Example 7
Source File: RedisRunner.java    From redisson with Apache License 2.0 5 votes vote down vote up
public RedisVersion getRedisVersion() {
    if (redisVersion == null) {
        RedisConnection c = createRedisClientInstance().connect();
        Map<String, String> serverMap = c.sync(RedisCommands.INFO_SERVER);
        redisVersion = new RedisVersion(serverMap.get("redis_version"));
        c.closeAsync();
    }
    return redisVersion;
}
 
Example 8
Source File: RedisRunner.java    From redisson with Apache License 2.0 5 votes vote down vote up
public RedisVersion getRedisVersion() {
    if (redisVersion == null) {
        RedisConnection c = createRedisClientInstance().connect();
        Map<String, String> serverMap = c.sync(RedisCommands.INFO_SERVER);
        redisVersion = new RedisVersion(serverMap.get("redis_version"));
        c.closeAsync();
    }
    return redisVersion;
}
 
Example 9
Source File: RedisRunner.java    From redisson with Apache License 2.0 5 votes vote down vote up
public RedisVersion getRedisVersion() {
    if (redisVersion == null) {
        RedisConnection c = createRedisClientInstance().connect();
        Map<String, String> serverMap = c.sync(RedisCommands.INFO_SERVER);
        redisVersion = new RedisVersion(serverMap.get("redis_version"));
        c.closeAsync();
    }
    return redisVersion;
}
 
Example 10
Source File: RedisRunner.java    From redisson with Apache License 2.0 5 votes vote down vote up
public RedisVersion getRedisVersion() {
    if (redisVersion == null) {
        RedisConnection c = createRedisClientInstance().connect();
        Map<String, String> serverMap = c.sync(RedisCommands.INFO_SERVER);
        redisVersion = new RedisVersion(serverMap.get("redis_version"));
        c.closeAsync();
    }
    return redisVersion;
}
 
Example 11
Source File: RedisRunner.java    From redisson with Apache License 2.0 5 votes vote down vote up
public RedisVersion getRedisVersion() {
    if (redisVersion == null) {
        RedisConnection c = createRedisClientInstance().connect();
        Map<String, String> serverMap = c.sync(RedisCommands.INFO_SERVER);
        redisVersion = new RedisVersion(serverMap.get("redis_version"));
        c.closeAsync();
    }
    return redisVersion;
}
 
Example 12
Source File: RedisRunner.java    From redisson with Apache License 2.0 5 votes vote down vote up
public RedisVersion getRedisVersion() {
    if (redisVersion == null) {
        RedisConnection c = createRedisClientInstance().connect();
        Map<String, String> serverMap = c.sync(RedisCommands.INFO_SERVER);
        redisVersion = new RedisVersion(serverMap.get("redis_version"));
        c.closeAsync();
    }
    return redisVersion;
}
 
Example 13
Source File: RedisClientTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testBigRequest() throws InterruptedException, ExecutionException {
    RedisConnection conn = redisClient.connect();

    for (int i = 0; i < 50; i++) {
        conn.sync(StringCodec.INSTANCE, RedisCommands.HSET, "testmap", i, "2");
    }

    Map<Object, Object> res = conn.sync(StringCodec.INSTANCE, RedisCommands.HGETALL, "testmap");
    assertThat(res.size()).isEqualTo(50);

    conn.sync(RedisCommands.FLUSHDB);
}
 
Example 14
Source File: RedissonIntegrationTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenLowLevelRedisCommands_thenExecuteLowLevelCommandsOnRedis(){
    RedisClientConfig redisClientConfig = new RedisClientConfig();
    redisClientConfig.setAddress("localhost", 6379);
    RedisClient client = RedisClient.create(redisClientConfig);
    RedisConnection conn = client.connect();
    conn.sync(StringCodec.INSTANCE, RedisCommands.SET, "test", 0);

    String testValue = conn.sync(StringCodec.INSTANCE, RedisCommands.GET, "test");

    conn.closeAsync();
    client.shutdown();

    assertTrue(testValue.equals("0"));
}