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


Java JedisPool.returnBrokenResource方法代碼示例

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


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

示例1: isAvailable

import redis.clients.jedis.JedisPool; //導入方法依賴的package包/類
public boolean isAvailable() {
    for (JedisPool jedisPool : jedisPools.values()) {
        Jedis jedis = jedisPool.getResource();
        boolean isBroken = false;
        try {
            if (jedis.isConnected()) {
                return true; // 至少需單台機器可用
            }
        } catch (JedisConnectionException e) {
            isBroken = true;
        } finally {
            if (isBroken) {
                jedisPool.returnBrokenResource(jedis);
            } else {
                jedisPool.returnResource(jedis);
            }
        }
    }
    return false;
}
 
開發者ID:zhuxiaolei,項目名稱:dubbo2,代碼行數:21,代碼來源:RedisRegistry.java

示例2: checkPoolRepairedWhenJedisIsBroken

import redis.clients.jedis.JedisPool; //導入方法依賴的package包/類
@Test
public void checkPoolRepairedWhenJedisIsBroken() {
  JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort());
  Jedis jedis = pool.getResource();
  jedis.auth("foobared");
  jedis.quit();
  pool.returnBrokenResource(jedis);

  jedis = pool.getResource();
  jedis.auth("foobared");
  jedis.incr("foo");
  pool.returnResource(jedis);
  pool.destroy();
  assertTrue(pool.isClosed());
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:16,代碼來源:JedisPoolTest.java

示例3: returnNullObjectShouldNotFail

import redis.clients.jedis.JedisPool; //導入方法依賴的package包/類
@Test
public void returnNullObjectShouldNotFail() {
  JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort(), 2000,
      "foobared", 0, "my_shiny_client_name");

  pool.returnBrokenResource(null);
  pool.returnResource(null);
  pool.returnResourceObject(null);
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:10,代碼來源:JedisPoolTest.java

示例4: deferExpired

import redis.clients.jedis.JedisPool; //導入方法依賴的package包/類
private void deferExpired() {
    for (Map.Entry<String, JedisPool> entry : jedisPools.entrySet()) {
        JedisPool jedisPool = entry.getValue();
        boolean isBroken = false;
        try {
            Jedis jedis = jedisPool.getResource();
            try {
                for (URL url : new HashSet<URL>(getRegistered())) {
                    if (url.getParameter(Constants.DYNAMIC_KEY, true)) {
                        String key = toCategoryPath(url);
                        if (jedis.hset(key, url.toFullString(), String.valueOf(System.currentTimeMillis() + expirePeriod)) == 1) {
                            jedis.publish(key, Constants.REGISTER);
                        }
                    }
                }
                if (admin) {
                    clean(jedis);
                }
                if (!replicate) {
                    break;//  如果服務器端已同步數據,隻需寫入單台機器
                }
            } catch (JedisConnectionException e){
                isBroken = true;
            } finally {
                if(isBroken){
                    jedisPool.returnBrokenResource(jedis);
                } else {
                    jedisPool.returnResource(jedis);
                }
            }
        } catch (Throwable t) {
            logger.warn("Failed to write provider heartbeat to redis registry. registry: " + entry.getKey() + ", cause: " + t.getMessage(), t);
        }
    }
}
 
開發者ID:zhuxiaolei,項目名稱:dubbo2,代碼行數:36,代碼來源:RedisRegistry.java


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