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


Java JedisSentinelPool.getResource方法代码示例

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


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

示例1: checkResourceIsCloseable

import redis.clients.jedis.JedisSentinelPool; //导入方法依赖的package包/类
@Test
public void checkResourceIsCloseable() {
  GenericObjectPoolConfig config = new GenericObjectPoolConfig();
  config.setMaxTotal(1);
  config.setBlockWhenExhausted(false);
  JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, config, 1000,
      "foobared", 2);

  Jedis jedis = pool.getResource();
  try {
    jedis.set("hello", "jedis");
  } finally {
    jedis.close();
  }

  Jedis jedis2 = pool.getResource();
  try {
    assertEquals(jedis, jedis2);
  } finally {
    jedis2.close();
  }
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:23,代码来源:JedisSentinelPoolTest.java

示例2: customClientName

import redis.clients.jedis.JedisSentinelPool; //导入方法依赖的package包/类
@Test
public void customClientName() {
  GenericObjectPoolConfig config = new GenericObjectPoolConfig();
  config.setMaxTotal(1);
  config.setBlockWhenExhausted(false);
  JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, config, 1000,
      "foobared", 0, "my_shiny_client_name");

  Jedis jedis = pool.getResource();

  try {
    assertEquals("my_shiny_client_name", jedis.clientGetname());
  } finally {
    jedis.close();
    pool.destroy();
  }

  assertTrue(pool.isClosed());
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:20,代码来源:JedisSentinelPoolTest.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().intValue());

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

示例4: 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

示例5: 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

示例6: checkCloseableConnections

import redis.clients.jedis.JedisSentinelPool; //导入方法依赖的package包/类
@Test
public void checkCloseableConnections() throws Exception {
  GenericObjectPoolConfig config = new GenericObjectPoolConfig();

  JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, config, 1000,
      "foobared", 2);
  Jedis jedis = pool.getResource();
  jedis.auth("foobared");
  jedis.set("foo", "bar");
  assertEquals("bar", jedis.get("foo"));
  pool.returnResource(jedis);
  pool.close();
  assertTrue(pool.isClosed());
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:15,代码来源:JedisSentinelPoolTest.java

示例7: returningBorrowedInstanceBeforeFailoverShouldNotAffectBorrowing

import redis.clients.jedis.JedisSentinelPool; //导入方法依赖的package包/类
@Test
public void returningBorrowedInstanceBeforeFailoverShouldNotAffectBorrowing()
    throws InterruptedException {
  final JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels,
      new GenericObjectPoolConfig(), 2000, "foobared", 2);

  Jedis borrowed = pool.getResource();
  forceFailover(pool);

  Thread.sleep(1000);

  // returns instance which was borrowed before failover
  borrowed.close();

  final AtomicBoolean isBorrowed = new AtomicBoolean(false);

  Thread t = new Thread(new Runnable() {
    @Override
    public void run() {
      pool.getResource();
      isBorrowed.set(true);
    }
  });
  t.start();

  // wait for 5 secs
  t.join(5000);

  assertTrue(isBorrowed.get());
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:31,代码来源:JedisSentinelPoolTest.java

示例8: returnResourceShouldResetState

import redis.clients.jedis.JedisSentinelPool; //导入方法依赖的package包/类
@Test
public void returnResourceShouldResetState() {
  GenericObjectPoolConfig config = new GenericObjectPoolConfig();
  config.setMaxTotal(1);
  config.setBlockWhenExhausted(false);
  JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, config, 1000,
      "foobared", 2);

  Jedis jedis = pool.getResource();
  Jedis jedis2 = null;

  try {
    jedis.set("hello", "jedis");
    Transaction t = jedis.multi();
    t.set("hello", "world");
    pool.returnResource(jedis);

    jedis2 = pool.getResource();

    assertTrue(jedis == jedis2);
    assertEquals("jedis", jedis2.get("hello"));
  } catch (JedisConnectionException e) {
    if (jedis2 != null) {
      pool.returnBrokenResource(jedis2);
      jedis2 = null;
    }
  } finally {
    if (jedis2 != null) jedis2.close();

    pool.destroy();
  }
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:33,代码来源:JedisSentinelPoolTest.java

示例9: testSentinelExample

import redis.clients.jedis.JedisSentinelPool; //导入方法依赖的package包/类
@Test
    public void testSentinelExample() {
        JedisSentinelPool sentinelPool = null;

        // 使用默认配置
//        sentinelPool = ClientBuilder.redisSentinel(appId).build();

        /**
         * 自定义配置
         */
        GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
        poolConfig.setMaxIdle(GenericObjectPoolConfig.DEFAULT_MAX_IDLE * 3);
        poolConfig.setMinIdle(GenericObjectPoolConfig.DEFAULT_MIN_IDLE * 2);
        poolConfig.setJmxEnabled(true);
        poolConfig.setMaxWaitMillis(3000);

        sentinelPool = ClientBuilder.redisSentinel(appId)
                .setPoolConfig(poolConfig)
                .setConnectionTimeout(2000)
                .setSoTimeout(1000)
                .build();

        Jedis jedis = sentinelPool.getResource();
        jedis.set("key1", "1");
        assertEquals("2", jedis.incr("key1"));
        jedis.close();
    }
 
开发者ID:sohutv,项目名称:cachecloud,代码行数:28,代码来源:RedisSentinelTest.java

示例10: checkCloseableConnections

import redis.clients.jedis.JedisSentinelPool; //导入方法依赖的package包/类
@Test
public void checkCloseableConnections() throws Exception {
  GenericObjectPoolConfig config = new GenericObjectPoolConfig();

  JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, config, 1000,
      "foobared", 2);
  Jedis jedis = pool.getResource();
  jedis.auth("foobared");
  jedis.set("foo", "bar");
  assertEquals("bar", jedis.get("foo"));
  jedis.close();
  pool.close();
  assertTrue(pool.isClosed());
}
 
开发者ID:sohutv,项目名称:cachecloud,代码行数:15,代码来源:JedisSentinelPoolTest.java

示例11: returnResourceShouldResetState

import redis.clients.jedis.JedisSentinelPool; //导入方法依赖的package包/类
@Test
public void returnResourceShouldResetState() {
  GenericObjectPoolConfig config = new GenericObjectPoolConfig();
  config.setMaxTotal(1);
  config.setBlockWhenExhausted(false);
  JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, config, 1000,
      "foobared", 2);

  Jedis jedis = pool.getResource();
  Jedis jedis2 = null;

  try {
    jedis.set("hello", "jedis");
    Transaction t = jedis.multi();
    t.set("hello", "world");
    jedis.close();

    jedis2 = pool.getResource();

    assertTrue(jedis == jedis2);
    assertEquals("jedis", jedis2.get("hello"));
  } catch (JedisConnectionException e) {
    if (jedis2 != null) {
      jedis2 = null;
    }
  } finally {
    jedis2.close();

    pool.destroy();
  }
}
 
开发者ID:sohutv,项目名称:cachecloud,代码行数:32,代码来源:JedisSentinelPoolTest.java

示例12: addSentinel

import redis.clients.jedis.JedisSentinelPool; //导入方法依赖的package包/类
@Override
public boolean addSentinel(long appId, String sentinelHost) {
    AppDesc appDesc = appDao.getAppDescById(appId);
    JedisSentinelPool jedisSentinelPool = redisCenter.getJedisSentinelPool(appDesc);
    if (jedisSentinelPool == null) {
        return false;
    }
    List<InstanceInfo> instanceInfos = instanceDao.getInstListByAppId(appId);
    String masterName = null;
    for (Iterator<InstanceInfo> i = instanceInfos.iterator(); i.hasNext(); ) {
        InstanceInfo instanceInfo = i.next();
        if (instanceInfo.getType() != ConstUtils.CACHE_REDIS_SENTINEL) {
            i.remove();
            continue;
        }
        if (masterName == null && StringUtils.isNotBlank(instanceInfo.getCmd())) {
            masterName = instanceInfo.getCmd();
        }
    }
    Jedis jedis = null;
    String masterHost = null;
    Integer masterPort = null;
    try {
        jedis = jedisSentinelPool.getResource();
        masterHost = jedis.getClient().getHost();
        masterPort = jedis.getClient().getPort();
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    } finally {
        jedis.close();
        jedisSentinelPool.destroy();
    }
    boolean isRun = runSentinel(appDesc, sentinelHost, masterName, masterHost, masterPort);
    if (!isRun) {
        return false;
    }
    return true;
}
 
开发者ID:sohutv,项目名称:cachecloud,代码行数:39,代码来源:RedisDeployCenterImpl.java

示例13: test

import redis.clients.jedis.JedisSentinelPool; //导入方法依赖的package包/类
@Test
public void test() {
	GenericObjectPoolConfig config = new GenericObjectPoolConfig();
	config.setMaxTotal(1);
	config.setBlockWhenExhausted(false);
	Set<String> sentinels = new HashSet<String>();
	sentinels.add(new HostAndPort("192.168.0.36", 26379).toString());
	JedisSentinelPool pool = new JedisSentinelPool("mymaster", sentinels,
			config, 10000000);
	Jedis jedis = pool.getResource();

	Jedis jedis2 = null;

	try {
		jedis.set("hello", "jedis");
		Transaction t = jedis.multi();
		t.set("hello", "world");
		pool.returnResource(jedis);

		jedis2 = pool.getResource();

		assertTrue(jedis == jedis2);
		assertEquals("jedis", jedis2.get("hello"));
	} catch (JedisConnectionException e) {
		if (jedis2 != null) {
			pool.returnBrokenResource(jedis2);
			jedis2 = null;
		}
	} finally {
		if (jedis2 != null)
			pool.returnResource(jedis2);

		pool.destroy();
	}

}
 
开发者ID:zhangxinhang,项目名称:mds,代码行数:37,代码来源:SentinelTest.java

示例14: main

import redis.clients.jedis.JedisSentinelPool; //导入方法依赖的package包/类
public static void main(String[] args) {
	GenericObjectPoolConfig config = new GenericObjectPoolConfig();
	config.setMaxTotal(1);
	config.setBlockWhenExhausted(false);
	Set<String> sentinels = new HashSet<String>();
	sentinels.add(new HostAndPort("192.168.0.36", 26379).toString());
	JedisSentinelPool pool = new JedisSentinelPool("mymaster", sentinels,
			config, 10000000);
	Jedis jedis = pool.getResource();
	jedis.set("hello", "world");
	System.out.println(jedis.get("hello"));
	pool.destroy();
}
 
开发者ID:zhangxinhang,项目名称:mds,代码行数:14,代码来源:SentinelTest.java

示例15: setUpRedis

import redis.clients.jedis.JedisSentinelPool; //导入方法依赖的package包/类
@Before
public void setUpRedis() throws IOException, SchedulerConfigException {
    final List<Integer> sentinels = Arrays.asList(getPort(), getPort());
    final List<Integer> group1 = Arrays.asList(getPort(), getPort());
    final List<Integer> group2 = Arrays.asList(getPort(), getPort());
    //creates a cluster with 3 sentinels, quorum size of 2 and 3 replication groups, each with one master and one slave
    redisCluster = RedisCluster.builder().sentinelPorts(sentinels).quorumSize(2)
        .serverPorts(group1).replicationGroup("master1", 1)
        .serverPorts(group2).replicationGroup("master2", 1)
        .ephemeralServers().replicationGroup("master3", 1)
        .build();
    redisCluster.start();


    Set<String> jedisSentinelHosts = JedisUtil.sentinelHosts(redisCluster);

    joinedHosts = Joiner.on(",").join(jedisSentinelHosts);

    final short database = 1;
    JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
    jedisPoolConfig.setTestOnBorrow(true);
    jedisPoolConfig.setTestOnCreate(true);
    jedisPoolConfig.setTestOnReturn(true);
    jedisPoolConfig.setMaxWaitMillis(2000);
    jedisPoolConfig.setMaxTotal(20);
    jedisPool = new JedisSentinelPool("master1", jedisSentinelHosts, jedisPoolConfig);
    jobStore = new RedisJobStore();
    jobStore.setHost(joinedHosts);
    jobStore.setJedisPool(jedisSentinelPool);
    jobStore.setLockTimeout(2000);
    jobStore.setMasterGroupName("master1");
    jobStore.setRedisSentinel(true);
    jobStore.setInstanceId("testJobStore1");
    jobStore.setDatabase(database);
    mockScheduleSignaler = mock(SchedulerSignaler.class);
    jobStore.initialize(null, mockScheduleSignaler);
    schema = new RedisJobStoreSchema();

    jedis = jedisPool.getResource();
    jedis.flushDB();

}
 
开发者ID:jlinn,项目名称:quartz-redis-jobstore,代码行数:43,代码来源:RedisSentinelJobStoreTest.java


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