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


Java JedisPool.destroy方法代碼示例

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


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

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

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

示例3: selectDatabaseOnActivation

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

  Jedis jedis0 = pool.getResource();
  assertEquals(0L, jedis0.getDB().longValue());

  jedis0.select(1);
  assertEquals(1L, jedis0.getDB().longValue());

  pool.returnResource(jedis0);

  Jedis jedis1 = pool.getResource();
  assertTrue("Jedis instance was not reused", jedis1 == jedis0);
  assertEquals(0L, jedis1.getDB().longValue());

  pool.returnResource(jedis1);
  pool.destroy();
  assertTrue(pool.isClosed());
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:22,代碼來源:JedisPoolTest.java

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

示例5: testAddObject

import redis.clients.jedis.JedisPool; //導入方法依賴的package包/類
@Test
public void testAddObject() {
  JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort(), 2000);
  pool.addObjects(1);
  assertEquals(pool.getNumIdle(), 1);
  pool.destroy();

}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:9,代碼來源:JedisPoolTest.java

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

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

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

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

示例10: customClientName

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

  Jedis jedis = pool0.getResource();

  assertEquals("my_shiny_client_name", jedis.clientGetname());

  pool0.returnResource(jedis);
  pool0.destroy();
  assertTrue(pool0.isClosed());
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:14,代碼來源:JedisPoolTest.java

示例11: returnResourceShouldResetState

import redis.clients.jedis.JedisPool; //導入方法依賴的package包/類
@Test
public void returnResourceShouldResetState() {
  GenericObjectPoolConfig config = new GenericObjectPoolConfig();
  config.setMaxTotal(1);
  config.setBlockWhenExhausted(false);
  JedisPool pool = new JedisPool(config, hnp.getHost(), hnp.getPort(), 2000, "foobared");

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

  Jedis jedis2 = pool.getResource();
  try {
    assertTrue(jedis == jedis2);
    assertEquals("jedis", jedis2.get("hello"));
  } finally {
    jedis2.close();
  }

  pool.destroy();
  assertTrue(pool.isClosed());
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:28,代碼來源:JedisPoolTest.java

示例12: getNumActiveIsNegativeWhenPoolIsClosed

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

  pool.destroy();
  assertTrue(pool.getNumActive() < 0);
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:9,代碼來源:JedisPoolTest.java

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

示例14: doTest

import redis.clients.jedis.JedisPool; //導入方法依賴的package包/類
private static void doTest() throws Exception {
    GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
    poolConfig.setMinIdle(0);
    poolConfig.setMaxIdle(5);
    poolConfig.setMaxTotal(5);
    final JedisPool pool = new JedisPool(poolConfig, "127.0.0.1", 6379, 2000, "weimob123", 8);

    List<Thread> tds = new ArrayList<Thread>();
    final Integer temp = 0;
    final AtomicInteger ind = new AtomicInteger();
    for (int i = 0; i < 50; i++) {
        Thread hj = new Thread(new Runnable() {
            public void run() {
                for (int i; (i = ind.getAndIncrement()) < TOTAL_OPERATIONS; ) {
                    Jedis j = pool.getResource();
                    final String key = "foo" + i;
                    // redisUtil.setRedisData(key, key);
                    j.set(key.getBytes(), ConvertUtil.serialize(temp));
                    j.close();
                }
            }
        });
        tds.add(hj);
        hj.start();
    }

    for (Thread t : tds)
        t.join();
    pool.close();
    pool.destroy();
}
 
開發者ID:TwoDragonLake,項目名稱:tdl-seckill,代碼行數:32,代碼來源:JedisTest.java

示例15: withPool

import redis.clients.jedis.JedisPool; //導入方法依賴的package包/類
private static void withPool() throws Exception {
    GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
    // poolConfig.setMinIdle(0);
    // poolConfig.setMaxIdle(5);
    // poolConfig.setMaxTotal(5);
    final JedisPool pool = new JedisPool(poolConfig, "127.0.0.1", 6379, 2000, "weimob123", 0);
    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 (; ind.getAndIncrement() < TOTAL_OPERATIONS; ) {
                    try {
                        Jedis j = pool.getResource();
                        // final String key = "foo" + i;
                        // j.setRedisData(key, key);
                        // j.getRedisData(key);
                        j.get("foo1");
                        j.close();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        });
        tds.add(hj);
        hj.start();
    }

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

    pool.destroy();

}
 
開發者ID:TwoDragonLake,項目名稱:tdl-seckill,代碼行數:37,代碼來源:PoolTest.java


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