当前位置: 首页>>代码示例>>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;未经允许,请勿转载。