Search in sources :

Example 6 with CommandsData

use of org.redisson.client.protocol.CommandsData in project redisson by redisson.

the class RedisClientTest method testPipeline.

@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);
    CompletableFuture<Void> p = new CompletableFuture<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);
}
Also used : ArrayList(java.util.ArrayList) CommandsData(org.redisson.client.protocol.CommandsData) CommandData(org.redisson.client.protocol.CommandData)

Aggregations

CommandData (org.redisson.client.protocol.CommandData)6 CommandsData (org.redisson.client.protocol.CommandsData)6 ArrayList (java.util.ArrayList)5 ChannelFuture (io.netty.channel.ChannelFuture)3 ChannelFutureListener (io.netty.channel.ChannelFutureListener)3 RedisAskException (org.redisson.client.RedisAskException)3 RedisConnection (org.redisson.client.RedisConnection)3 RedisLoadingException (org.redisson.client.RedisLoadingException)3 RedisMovedException (org.redisson.client.RedisMovedException)3 RedisTimeoutException (org.redisson.client.RedisTimeoutException)3 RedisTryAgainException (org.redisson.client.RedisTryAgainException)3 List (java.util.List)2 RedisException (org.redisson.client.RedisException)2 WriteRedisConnectionException (org.redisson.client.WriteRedisConnectionException)2 ChannelPromise (io.netty.channel.ChannelPromise)1 Timeout (io.netty.util.Timeout)1 TimerTask (io.netty.util.TimerTask)1 IOException (java.io.IOException)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1