コード例 #1
0
  private void updateClusterState(
      final ClusterServersConfig cfg, final RedisConnection connection) {
    Future<String> future = connection.async(RedisCommands.CLUSTER_NODES);
    future.addListener(
        new FutureListener<String>() {
          @Override
          public void operationComplete(Future<String> future) throws Exception {
            if (!future.isSuccess()) {
              log.error(
                  "Can't execute CLUSTER_NODES with " + connection.getRedisClient().getAddr(),
                  future.cause());
              scheduleClusterChangeCheck(cfg);
              return;
            }

            String nodesValue = future.getNow();
            log.debug(
                "cluster nodes state from {}:\n{}",
                connection.getRedisClient().getAddr(),
                nodesValue);

            Collection<ClusterPartition> newPartitions = parsePartitions(nodesValue);
            checkMasterNodesChange(newPartitions);
            checkSlaveNodesChange(newPartitions);
            checkSlotsChange(cfg, newPartitions);
            scheduleClusterChangeCheck(cfg);
          }
        });
  }
コード例 #2
0
  @Test
  public void test() throws InterruptedException {
    RedisClient c = new RedisClient("localhost", 6379);
    final RedisConnection conn = c.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);
  }
コード例 #3
0
 private void ping(RedisConnection c, final FutureListener<String> pingListener) {
   Future<String> f = c.async(RedisCommands.PING);
   f.addListener(pingListener);
 }