예제 #1
0
  @Test
  public void testPipeline() throws InterruptedException, ExecutionException {
    RedisClient c = new RedisClient("localhost", 6379);
    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);

    Promise<Void> p = c.getBootstrap().group().next().newPromise();
    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);
  }
예제 #2
0
  @Test
  public void testPipelineBigResponse() throws InterruptedException, ExecutionException {
    RedisClient c = new RedisClient("localhost", 6379);
    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);
    }

    Promise<Void> p = c.getBootstrap().group().next().newPromise();
    conn.send(new CommandsData(p, commands));

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

    conn.sync(RedisCommands.FLUSHDB);
  }