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


Java JedisPool.returnResource方法代码示例

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


在下文中一共展示了JedisPool.returnResource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: checkJedisIsReusedWhenReturned

import redis.clients.jedis.JedisPool; //导入方法依赖的package包/类
@Test
public void checkJedisIsReusedWhenReturned() {

  JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort());
  Jedis jedis = pool.getResource();
  jedis.auth("foobared");
  jedis.set("foo", "0");
  pool.returnResource(jedis);

  jedis = pool.getResource();
  jedis.auth("foobared");
  jedis.incr("foo");
  pool.returnResource(jedis);
  pool.destroy();
  assertTrue(pool.isClosed());
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:17,代码来源:JedisPoolTest.java

示例3: call

import redis.clients.jedis.JedisPool; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@Override
public <T> T call(JedisPool jedisPool) {
	Jedis jedis = null;
	try {
		jedis = jedisPool.getResource();
		return exec(jedis);
	} catch (Exception e) {
		logger.error("jedisPool getResouce or exec has exception");
		throw e;
	} finally {
		if (jedis != null) {
			jedisPool.returnResource(jedis);
		}
	}
}
 
开发者ID:zh-cn-trio,项目名称:trioAop,代码行数:17,代码来源:AbstractCommandCall.java

示例4: nonDefaultDatabase

import redis.clients.jedis.JedisPool; //导入方法依赖的package包/类
@Test
public void nonDefaultDatabase() {
  JedisPool pool0 = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort(), 2000,
      "foobared");
  Jedis jedis0 = pool0.getResource();
  jedis0.set("foo", "bar");
  assertEquals("bar", jedis0.get("foo"));
  pool0.returnResource(jedis0);
  pool0.destroy();
  assertTrue(pool0.isClosed());

  JedisPool pool1 = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort(), 2000,
      "foobared", 1);
  Jedis jedis1 = pool1.getResource();
  assertNull(jedis1.get("foo"));
  pool1.returnResource(jedis1);
  pool1.destroy();
  assertTrue(pool1.isClosed());
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:20,代码来源:JedisPoolTest.java

示例5: getNumActiveReturnsTheCorrectNumber

import redis.clients.jedis.JedisPool; //导入方法依赖的package包/类
@Test
public void getNumActiveReturnsTheCorrectNumber() {
  JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort(), 2000);
  Jedis jedis = pool.getResource();
  jedis.auth("foobared");
  jedis.set("foo", "bar");
  assertEquals("bar", jedis.get("foo"));

  assertEquals(1, pool.getNumActive());

  Jedis jedis2 = pool.getResource();
  jedis.auth("foobared");
  jedis.set("foo", "bar");

  assertEquals(2, pool.getNumActive());

  pool.returnResource(jedis);
  assertEquals(1, pool.getNumActive());

  pool.returnResource(jedis2);

  assertEquals(0, pool.getNumActive());

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

示例6: isAvailable

import redis.clients.jedis.JedisPool; //导入方法依赖的package包/类
public boolean isAvailable() {
    for (JedisPool jedisPool : jedisPools.values()) {
        try {
            Jedis jedis = jedisPool.getResource();
            try {
            	if (jedis.isConnected()) {
                    return true; // 至少需单台机器可用
                }
            } finally {
                jedisPool.returnResource(jedis);
            }
        } catch (Throwable t) {
        }
    }
    return false;
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:17,代码来源:RedisRegistry.java

示例7: checkConnections

import redis.clients.jedis.JedisPool; //导入方法依赖的package包/类
@Test
public void checkConnections() {
  JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort(), 2000);
  Jedis jedis = pool.getResource();
  jedis.auth("foobared");
  jedis.set("foo", "bar");
  assertEquals("bar", jedis.get("foo"));
  pool.returnResource(jedis);
  pool.destroy();
  assertTrue(pool.isClosed());
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:12,代码来源:JedisPoolTest.java

示例8: checkCloseableConnections

import redis.clients.jedis.JedisPool; //导入方法依赖的package包/类
@Test
public void checkCloseableConnections() throws Exception {
  JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort(), 2000);
  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,代码行数:12,代码来源:JedisPoolTest.java

示例9: checkConnectionWithDefaultPort

import redis.clients.jedis.JedisPool; //导入方法依赖的package包/类
@Test
public void checkConnectionWithDefaultPort() {
  JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort());
  Jedis jedis = pool.getResource();
  jedis.auth("foobared");
  jedis.set("foo", "bar");
  assertEquals("bar", jedis.get("foo"));
  pool.returnResource(jedis);
  pool.destroy();
  assertTrue(pool.isClosed());
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:12,代码来源:JedisPoolTest.java

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

示例11: securePool

import redis.clients.jedis.JedisPool; //导入方法依赖的package包/类
@Test
public void securePool() {
  JedisPoolConfig config = new JedisPoolConfig();
  config.setTestOnBorrow(true);
  JedisPool pool = new JedisPool(config, hnp.getHost(), hnp.getPort(), 2000, "foobared");
  Jedis jedis = pool.getResource();
  jedis.set("foo", "bar");
  pool.returnResource(jedis);
  pool.destroy();
  assertTrue(pool.isClosed());
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:12,代码来源:JedisPoolTest.java

示例12: 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:flychao88,项目名称:dubbocloud,代码行数:36,代码来源:RedisRegistry.java

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

示例14: withPool

import redis.clients.jedis.JedisPool; //导入方法依赖的package包/类
private static void withPool() throws Exception {
  final JedisPool pool = new JedisPool(new GenericObjectPoolConfig(), hnp.getHost(),
      hnp.getPort(), 2000, "foobared");
  List<Thread> tds = new ArrayList<Thread>();

  final AtomicInteger ind = new AtomicInteger();
  for (int i = 0; i < 50; i++) {
    Thread hj = new Thread(new Runnable() {
      public void run() {
        for (int i = 0; (i = ind.getAndIncrement()) < TOTAL_OPERATIONS;) {
          try {
            Jedis j = pool.getResource();
            final String key = "foo" + i;
            j.set(key, key);
            j.get(key);
            pool.returnResource(j);
          } catch (Exception e) {
            e.printStackTrace();
          }
        }
      }
    });
    tds.add(hj);
    hj.start();
  }

  for (Thread t : tds)
    t.join();

  pool.destroy();

}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:33,代码来源:PoolBenchmark.java

示例15: deferExpired

import redis.clients.jedis.JedisPool; //导入方法依赖的package包/类
private void deferExpired() {
    for (Map.Entry<String, JedisPool> entry : jedisPools.entrySet()) {
        JedisPool jedisPool = entry.getValue();
        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;//  如果服务器端已同步数据,只需写入单台机器
                }
            } finally {
                jedisPool.returnResource(jedis);
            }
        } catch (Throwable t) {
            logger.warn("Failed to write provider heartbeat to redis registry. registry: " + entry.getKey() + ", cause: " + t.getMessage(), t);
        }
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:29,代码来源:RedisRegistry.java


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