当前位置: 首页>>代码示例>>Java>>正文


Java JedisSentinelPool.getCurrentHostMaster方法代码示例

本文整理汇总了Java中redis.clients.jedis.JedisSentinelPool.getCurrentHostMaster方法的典型用法代码示例。如果您正苦于以下问题:Java JedisSentinelPool.getCurrentHostMaster方法的具体用法?Java JedisSentinelPool.getCurrentHostMaster怎么用?Java JedisSentinelPool.getCurrentHostMaster使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在redis.clients.jedis.JedisSentinelPool的用法示例。


在下文中一共展示了JedisSentinelPool.getCurrentHostMaster方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: forceFailover

import redis.clients.jedis.JedisSentinelPool; //导入方法依赖的package包/类
private void forceFailover(JedisSentinelPool pool) throws InterruptedException {
  HostAndPort oldMaster = pool.getCurrentHostMaster();

  // jedis connection should be master
  Jedis beforeFailoverJedis = pool.getResource();
  assertEquals("PONG", beforeFailoverJedis.ping());

  waitForFailover(pool, oldMaster);

  Jedis afterFailoverJedis = pool.getResource();
  assertEquals("PONG", afterFailoverJedis.ping());
  assertEquals("foobared", afterFailoverJedis.configGet("requirepass").get(1));
  assertEquals(2, afterFailoverJedis.getDB().intValue());

  // returning both connections to the pool should not throw
  beforeFailoverJedis.close();
  afterFailoverJedis.close();
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:19,代码来源:JedisSentinelPoolTest.java

示例2: testSentinel

import redis.clients.jedis.JedisSentinelPool; //导入方法依赖的package包/类
@Test
public void testSentinel() {
    JedisSentinelPool sentinelPool = ClientBuilder.redisSentinel(appId)
            .setConnectionTimeout(2000)
            .setSoTimeout(1000)
            .build();
    HostAndPort currentHostMaster = sentinelPool.getCurrentHostMaster();
    logger.info("current master: {}", currentHostMaster.toString());

    Jedis jedis = sentinelPool.getResource();
    for (int i = 0; i < 10; i++) {
        jedis.lpush("mylist", "list-" + i);
    }
    jedis.close();
    sentinelPool.destroy();
}
 
开发者ID:sohutv,项目名称:cachecloud,代码行数:17,代码来源:RedisSentinelTest.java

示例3: forceFailover

import redis.clients.jedis.JedisSentinelPool; //导入方法依赖的package包/类
private void forceFailover(JedisSentinelPool pool) throws InterruptedException {
  HostAndPort oldMaster = pool.getCurrentHostMaster();

  // jedis connection should be master
  Jedis beforeFailoverJedis = pool.getResource();
  assertEquals("PONG", beforeFailoverJedis.ping());

  waitForFailover(pool, oldMaster);

  Jedis afterFailoverJedis = pool.getResource();
  assertEquals("PONG", afterFailoverJedis.ping());
  assertEquals("foobared", afterFailoverJedis.configGet("requirepass").get(1));
  assertEquals(2, afterFailoverJedis.getDB());

  // returning both connections to the pool should not throw
  beforeFailoverJedis.close();
  afterFailoverJedis.close();
}
 
开发者ID:sohutv,项目名称:cachecloud,代码行数:19,代码来源:JedisSentinelPoolTest.java

示例4: waitForJedisSentinelPoolRecognizeNewMaster

import redis.clients.jedis.JedisSentinelPool; //导入方法依赖的package包/类
private void waitForJedisSentinelPoolRecognizeNewMaster(JedisSentinelPool pool,
    HostAndPort newMaster) throws InterruptedException {

  while (true) {
    HostAndPort currentHostMaster = pool.getCurrentHostMaster();

    if (newMaster.equals(currentHostMaster)) break;

    System.out.println("JedisSentinelPool's master is not yet changed, sleep...");

    Thread.sleep(100);
  }
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:14,代码来源:JedisSentinelPoolTest.java


注:本文中的redis.clients.jedis.JedisSentinelPool.getCurrentHostMaster方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。