當前位置: 首頁>>代碼示例>>Java>>正文


Java Jedis.sentinelGetMasterAddrByName方法代碼示例

本文整理匯總了Java中redis.clients.jedis.Jedis.sentinelGetMasterAddrByName方法的典型用法代碼示例。如果您正苦於以下問題:Java Jedis.sentinelGetMasterAddrByName方法的具體用法?Java Jedis.sentinelGetMasterAddrByName怎麽用?Java Jedis.sentinelGetMasterAddrByName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在redis.clients.jedis.Jedis的用法示例。


在下文中一共展示了Jedis.sentinelGetMasterAddrByName方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: sentinelFailover

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Test
public void sentinelFailover() throws InterruptedException {
  Jedis j = new Jedis(sentinelForFailover.getHost(), sentinelForFailover.getPort());
  Jedis j2 = new Jedis(sentinelForFailover.getHost(), sentinelForFailover.getPort());

  try {
    List<String> masterHostAndPort = j.sentinelGetMasterAddrByName(FAILOVER_MASTER_NAME);
    HostAndPort currentMaster = new HostAndPort(masterHostAndPort.get(0),
        Integer.parseInt(masterHostAndPort.get(1)));

    JedisSentinelTestUtil.waitForNewPromotedMaster(FAILOVER_MASTER_NAME, j, j2);

    masterHostAndPort = j.sentinelGetMasterAddrByName(FAILOVER_MASTER_NAME);
    HostAndPort newMaster = new HostAndPort(masterHostAndPort.get(0),
        Integer.parseInt(masterHostAndPort.get(1)));

    assertNotEquals(newMaster, currentMaster);
  } finally {
    j.close();
  }

}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:23,代碼來源:JedisSentinelTest.java

示例2: sentinel

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Test
public void sentinel() {
  Jedis j = new Jedis(sentinel.getHost(), sentinel.getPort());

  try {
    List<Map<String, String>> masters = j.sentinelMasters();

    boolean inMasters = false;
    for (Map<String, String> master : masters)
      if (MASTER_NAME.equals(master.get("name"))) inMasters = true;

    assertTrue(inMasters);

    List<String> masterHostAndPort = j.sentinelGetMasterAddrByName(MASTER_NAME);
    HostAndPort masterFromSentinel = new HostAndPort(masterHostAndPort.get(0),
        Integer.parseInt(masterHostAndPort.get(1)));
    assertEquals(master, masterFromSentinel);

    List<Map<String, String>> slaves = j.sentinelSlaves(MASTER_NAME);
    assertTrue(!slaves.isEmpty());
    assertEquals(master.getPort(), Integer.parseInt(slaves.get(0).get("master-port")));

    // DO NOT RE-RUN TEST TOO FAST, RESET TAKES SOME TIME TO... RESET
    assertEquals(Long.valueOf(1), j.sentinelReset(MASTER_NAME));
    assertEquals(Long.valueOf(0), j.sentinelReset("woof" + MASTER_NAME));
  } finally {
    j.close();
  }
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:30,代碼來源:JedisSentinelTest.java


注:本文中的redis.clients.jedis.Jedis.sentinelGetMasterAddrByName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。