Search in sources :

Example 21 with RedisConnection

use of org.redisson.client.RedisConnection in project redisson by redisson.

the class RedisClientTest method testPipeline.

@Test
public void testPipeline() throws InterruptedException, ExecutionException {
    RedisClient c = new RedisClient(RedisRunner.getDefaultRedisServerBindAddressAndPort());
    RedisConnection conn = c.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));
    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);
}
Also used : RedissonPromise(org.redisson.misc.RedissonPromise) ArrayList(java.util.ArrayList) RedisClient(org.redisson.client.RedisClient) CommandsData(org.redisson.client.protocol.CommandsData) CommandData(org.redisson.client.protocol.CommandData) RedisConnection(org.redisson.client.RedisConnection) Test(org.junit.Test)

Example 22 with RedisConnection

use of org.redisson.client.RedisConnection in project redisson by redisson.

the class RedisClientTest method testBigRequest.

@Test
public void testBigRequest() throws InterruptedException, ExecutionException {
    RedisClient c = new RedisClient(RedisRunner.getDefaultRedisServerBindAddressAndPort());
    RedisConnection conn = c.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);
}
Also used : RedisClient(org.redisson.client.RedisClient) RedisConnection(org.redisson.client.RedisConnection) Test(org.junit.Test)

Example 23 with RedisConnection

use of org.redisson.client.RedisConnection in project redisson by redisson.

the class RedisClientTest method testPipelineBigResponse.

@Test
public void testPipelineBigResponse() throws InterruptedException, ExecutionException {
    RedisClient c = new RedisClient(RedisRunner.getDefaultRedisServerBindAddressAndPort());
    RedisConnection conn = c.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));
    for (CommandData<?, ?> commandData : commands) {
        commandData.getPromise().get();
    }
    conn.sync(RedisCommands.FLUSHDB);
}
Also used : RedissonPromise(org.redisson.misc.RedissonPromise) ArrayList(java.util.ArrayList) RedisClient(org.redisson.client.RedisClient) CommandsData(org.redisson.client.protocol.CommandsData) CommandData(org.redisson.client.protocol.CommandData) RedisConnection(org.redisson.client.RedisConnection) Test(org.junit.Test)

Aggregations

RedisConnection (org.redisson.client.RedisConnection)23 FutureListener (io.netty.util.concurrent.FutureListener)7 ArrayList (java.util.ArrayList)7 RFuture (org.redisson.api.RFuture)7 RedisClient (org.redisson.client.RedisClient)7 RedisException (org.redisson.client.RedisException)7 Future (io.netty.util.concurrent.Future)6 Test (org.junit.Test)6 RedisConnectionException (org.redisson.client.RedisConnectionException)6 RPromise (org.redisson.misc.RPromise)5 ChannelFuture (io.netty.channel.ChannelFuture)4 ScheduledFuture (io.netty.util.concurrent.ScheduledFuture)4 CommandData (org.redisson.client.protocol.CommandData)4 CommandsData (org.redisson.client.protocol.CommandsData)4 RedissonPromise (org.redisson.misc.RedissonPromise)4 ChannelFutureListener (io.netty.channel.ChannelFutureListener)3 Timeout (io.netty.util.Timeout)3 TimerTask (io.netty.util.TimerTask)3 RedisAskException (org.redisson.client.RedisAskException)3 RedisLoadingException (org.redisson.client.RedisLoadingException)3