@Test
 public void connectToRedisUsingSentinelWithReconnect() throws Exception {
   RedisConnection<String, String> connect = sentinelClient.connect().sync();
   connect.ping();
   connect.quit();
   connect.ping();
   connect.close();
 }
Beispiel #2
0
  public static void main(String[] args) {
    // Syntax: redis://[password@]host[:port][/databaseNumber]
    RedisClient redisClient = new RedisClient(RedisURI.create("redis://password@localhost:6379/0"));
    RedisConnection<String, String> connection = redisClient.connect();
    System.out.println("Connected to Redis");

    connection.set("foo", "bar");
    String value = connection.get("foo");
    System.out.println(value);

    connection.close();
    redisClient.shutdown();
  }
  @Test
  public void sentinelConnectWith() throws Exception {

    RedisClient client =
        new RedisClient(
            RedisURI.Builder.sentinel(TestSettings.host(), 1234, MASTER_ID)
                .withSentinel(TestSettings.host())
                .build());

    RedisSentinelAsyncCommands<String, String> sentinelConnection = client.connectSentinelAsync();
    assertThat(sentinelConnection.ping().get()).isEqualTo("PONG");

    sentinelConnection.close();

    RedisConnection<String, String> connection2 = client.connect().sync();
    assertThat(connection2.ping()).isEqualTo("PONG");
    connection2.quit();

    Wait.untilTrue(connection2::isOpen).waitOrTimeout();

    assertThat(connection2.ping()).isEqualTo("PONG");
    connection2.close();
    FastShutdown.shutdown(client);
  }