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


Java ShardedJedisPool.getResource方法代碼示例

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


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

示例1: checkResourceIsCloseable

import redis.clients.jedis.ShardedJedisPool; //導入方法依賴的package包/類
@Test
public void checkResourceIsCloseable() throws URISyntaxException {
  GenericObjectPoolConfig config = new GenericObjectPoolConfig();
  config.setMaxTotal(1);
  config.setBlockWhenExhausted(false);

  List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
  shards.add(new JedisShardInfo(new URI("redis://:[email protected]:6380")));
  shards.add(new JedisShardInfo(new URI("redis://:[email protected]:6379")));

  ShardedJedisPool pool = new ShardedJedisPool(config, shards);

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

  ShardedJedis jedis2 = pool.getResource();
  try {
    assertEquals(jedis, jedis2);
  } finally {
    jedis2.close();
  }
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:27,代碼來源:ShardedJedisPoolTest.java

示例2: getJedis

import redis.clients.jedis.ShardedJedisPool; //導入方法依賴的package包/類
public ShardedJedis getJedis(final String poolName) {
    Assert.hasText(poolName);
    ShardedJedis shardedJedis = null;
    try {
        final ShardedJedisPool pool = jedisPool.get(poolName);
        if (pool != null) {
            shardedJedis = pool.getResource();
        }

        Assert.notNull(shardedJedis, "Not found ShardedJedis.");
        return shardedJedis;
    } catch (final Throwable e) {
        close(shardedJedis);
        throw new RedisClientException(e.getMessage(), e);
    }
}
 
開發者ID:nano-projects,項目名稱:nano-framework,代碼行數:17,代碼來源:RedisClientPool.java

示例3: testShardSimplePool

import redis.clients.jedis.ShardedJedisPool; //導入方法依賴的package包/類
/**
 * 分布式連接池同步調用
 * 1.288 seconds
 * 1.291 seconds
 */
@Test
public void testShardSimplePool() {
	List<JedisShardInfo> shards = Arrays.asList(new JedisShardInfo(
			"localhost", 6379), new JedisShardInfo("localhost", 6379));

	ShardedJedisPool pool = new ShardedJedisPool(new JedisPoolConfig(), shards);
	ShardedJedis one = pool.getResource();

	long start = System.currentTimeMillis();
	for (int i = 0; i < COUNTER; i++) {
		String result = one.set("spn" + i, "n" + i);
	}
	long end = System.currentTimeMillis();
	pool.returnResource(one);
	logger.info("[email protected] SET: " + ((end - start) / 1000.0) + " seconds");

	pool.destroy();
}
 
開發者ID:leopardoooo,項目名稱:easyooo-framework,代碼行數:24,代碼來源:JedisApiTest.java

示例4: testShardPipelinedPool

import redis.clients.jedis.ShardedJedisPool; //導入方法依賴的package包/類
/**
 * 分布式連接池異步調用
 * 0.452 seconds
 * 0.43 seconds
 */
@Test
@Ignore
public void testShardPipelinedPool() {
    List<JedisShardInfo> shards = Arrays.asList(
            new JedisShardInfo("localhost",6379),
            new JedisShardInfo("localhost",6379));

    ShardedJedisPool pool = new ShardedJedisPool(new JedisPoolConfig(), shards);
    ShardedJedis one = pool.getResource();
    ShardedJedisPipeline pipeline = one.pipelined();
    
    long start = System.currentTimeMillis();
    for (int i = 0; i < COUNTER; i++) {
        pipeline.set("sppn" + i, "n" + i);
    }
    List<Object> results = pipeline.syncAndReturnAll();
    long end = System.currentTimeMillis();
    pool.returnResource(one);
    logger.info("[email protected] SET: " + ((end - start)/1000.0) + " seconds");
    pool.destroy();
}
 
開發者ID:leopardoooo,項目名稱:easyooo-framework,代碼行數:27,代碼來源:JedisApiTest.java

示例5: main

import redis.clients.jedis.ShardedJedisPool; //導入方法依賴的package包/類
/**
 * @param args
 */
public static void main(String[] args) {
	List<JedisShardInfo> list = new LinkedList<JedisShardInfo>();
	JedisShardInfo jedisShardInfo1 = new JedisShardInfo(ip1, port);
	jedisShardInfo1.setPassword(JedisConstant.password);
	list.add(jedisShardInfo1);
	JedisShardInfo jedisShardInfo2 = new JedisShardInfo(ip2, port);
	jedisShardInfo2.setPassword(JedisConstant.password);
	list.add(jedisShardInfo2);
	ShardedJedisPool pool = new ShardedJedisPool(config, list);
	for (int i = 0; i < 2000; i++) {
		ShardedJedis jedis = pool.getResource();
		String key = "howsun_" + i;
		//jedis.set(key, UUID.randomUUID().toString());
		System.out.println(key + "\t" + jedis.get(key) + "\t" + jedis.toString());
		pool.returnResource(jedis);
	}
}
 
開發者ID:howsun,項目名稱:howsun-javaee-framework,代碼行數:21,代碼來源:JedisShartClient.java

示例6: checkConnections

import redis.clients.jedis.ShardedJedisPool; //導入方法依賴的package包/類
@Test
public void checkConnections() {
  ShardedJedisPool pool = new ShardedJedisPool(new GenericObjectPoolConfig(), shards);
  ShardedJedis jedis = pool.getResource();
  jedis.set("foo", "bar");
  assertEquals("bar", jedis.get("foo"));
  pool.returnResource(jedis);
  pool.destroy();
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:10,代碼來源:ShardedJedisPoolTest.java

示例7: checkCloseableConnections

import redis.clients.jedis.ShardedJedisPool; //導入方法依賴的package包/類
@Test
public void checkCloseableConnections() throws Exception {
  ShardedJedisPool pool = new ShardedJedisPool(new GenericObjectPoolConfig(), shards);
  ShardedJedis jedis = pool.getResource();
  jedis.set("foo", "bar");
  assertEquals("bar", jedis.get("foo"));
  pool.returnResource(jedis);
  pool.close();
  assertTrue(pool.isClosed());
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:11,代碼來源:ShardedJedisPoolTest.java

示例8: checkConnectionWithDefaultPort

import redis.clients.jedis.ShardedJedisPool; //導入方法依賴的package包/類
@Test
public void checkConnectionWithDefaultPort() {
  ShardedJedisPool pool = new ShardedJedisPool(new GenericObjectPoolConfig(), shards);
  ShardedJedis jedis = pool.getResource();
  jedis.set("foo", "bar");
  assertEquals("bar", jedis.get("foo"));
  pool.returnResource(jedis);
  pool.destroy();
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:10,代碼來源:ShardedJedisPoolTest.java

示例9: checkJedisIsReusedWhenReturned

import redis.clients.jedis.ShardedJedisPool; //導入方法依賴的package包/類
@Test
public void checkJedisIsReusedWhenReturned() {
  ShardedJedisPool pool = new ShardedJedisPool(new GenericObjectPoolConfig(), shards);
  ShardedJedis jedis = pool.getResource();
  jedis.set("foo", "0");
  pool.returnResource(jedis);

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

示例10: checkPoolRepairedWhenJedisIsBroken

import redis.clients.jedis.ShardedJedisPool; //導入方法依賴的package包/類
@Test
public void checkPoolRepairedWhenJedisIsBroken() {
  ShardedJedisPool pool = new ShardedJedisPool(new GenericObjectPoolConfig(), shards);
  ShardedJedis jedis = pool.getResource();
  jedis.disconnect();
  pool.returnBrokenResource(jedis);

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

示例11: checkPoolOverflow

import redis.clients.jedis.ShardedJedisPool; //導入方法依賴的package包/類
@Test(expected = JedisException.class)
public void checkPoolOverflow() {
  GenericObjectPoolConfig config = new GenericObjectPoolConfig();
  config.setMaxTotal(1);
  config.setBlockWhenExhausted(false);

  ShardedJedisPool pool = new ShardedJedisPool(config, shards);

  ShardedJedis jedis = pool.getResource();
  jedis.set("foo", "0");

  ShardedJedis newJedis = pool.getResource();
  newJedis.incr("foo");
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:15,代碼來源:ShardedJedisPoolTest.java

示例12: shouldNotShareInstances

import redis.clients.jedis.ShardedJedisPool; //導入方法依賴的package包/類
@Test
public void shouldNotShareInstances() {
  GenericObjectPoolConfig config = new GenericObjectPoolConfig();
  config.setMaxTotal(2);

  ShardedJedisPool pool = new ShardedJedisPool(config, shards);

  ShardedJedis j1 = pool.getResource();
  ShardedJedis j2 = pool.getResource();

  assertNotSame(j1.getShard("foo"), j2.getShard("foo"));
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:13,代碼來源:ShardedJedisPoolTest.java

示例13: checkFailedJedisServer

import redis.clients.jedis.ShardedJedisPool; //導入方法依賴的package包/類
@Test
public void checkFailedJedisServer() {
  ShardedJedisPool pool = new ShardedJedisPool(new GenericObjectPoolConfig(), shards);
  ShardedJedis jedis = pool.getResource();
  jedis.incr("foo");
  pool.returnResource(jedis);
  pool.destroy();
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:9,代碼來源:ShardedJedisPoolTest.java

示例14: returnResourceShouldResetState

import redis.clients.jedis.ShardedJedisPool; //導入方法依賴的package包/類
@Test
public void returnResourceShouldResetState() throws URISyntaxException {
  GenericObjectPoolConfig config = new GenericObjectPoolConfig();
  config.setMaxTotal(1);
  config.setBlockWhenExhausted(false);

  List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
  shards.add(new JedisShardInfo(new URI("redis://:[email protected]:6380")));
  shards.add(new JedisShardInfo(new URI("redis://:[email protected]:6379")));

  ShardedJedisPool pool = new ShardedJedisPool(config, shards);

  ShardedJedis jedis = pool.getResource();
  jedis.set("pipelined", String.valueOf(0));
  jedis.set("pipelined2", String.valueOf(0));

  ShardedJedisPipeline pipeline = jedis.pipelined();

  pipeline.incr("pipelined");
  pipeline.incr("pipelined2");

  jedis.resetState();

  pipeline = jedis.pipelined();
  pipeline.incr("pipelined");
  pipeline.incr("pipelined2");
  List<Object> results = pipeline.syncAndReturnAll();

  assertEquals(2, results.size());
  pool.returnResource(jedis);
  pool.destroy();
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:33,代碼來源:ShardedJedisPoolTest.java

示例15: ShardedJedisCache

import redis.clients.jedis.ShardedJedisPool; //導入方法依賴的package包/類
/**
 * redis分片緩存
 * @param shardedJedisPool 分片池
 * @param reConnectPercent 百分比
 * @param reConnectTimeout 重連毫秒值
 */
public ShardedJedisCache(ShardedJedisPool shardedJedisPool, int reConnectPercent, int reConnectTimeout) {
	super();
	this.shardedJedis = shardedJedisPool.getResource();
	this.reConnectPercent = reConnectPercent;
	this.reConnectTimeout = reConnectTimeout;
}
 
開發者ID:shuiguang,項目名稱:ipwatch-java,代碼行數:13,代碼來源:ShardedJedisCache.java


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