Java Code Examples for redis.clients.jedis.JedisPool#close()
The following examples show how to use
redis.clients.jedis.JedisPool#close() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DoTestJedisHookProxy.java From uavstack with Apache License 2.0 | 5 votes |
private static void foo2() { System.out.println("TEST JedisPool ======================================================"); JedisPoolConfig cfg = new JedisPoolConfig(); cfg.setMaxTotal(5); cfg.setMaxIdle(1); cfg.setMaxWaitMillis(10000L); JedisPool jp = new JedisPool(cfg, ip, port); Jedis jedis = jp.getResource(); jedis.set("foo", "bar"); // jedis.close(); jedis = jp.getResource(); jedis.get("foo"); // jedis.close(); jedis = jp.getResource(); jedis.lpush("lll", "a"); jedis.lpush("lll", "b"); jedis.lpush("lll", "c"); jedis.lpop("lll"); jedis.lpop("lll"); jedis.lpop("lll"); // jedis.close(); jedis = jp.getResource(); jedis.hset("mmm", "abc", "123"); jedis.hset("mmm", "def", "456"); jedis.hgetAll("mmm"); jp.close(); }
Example 2
Source File: JedisPoolTest.java From cachecloud with Apache License 2.0 | 5 votes |
@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")); jedis.close(); pool.close(); assertTrue(pool.isClosed()); }
Example 3
Source File: DFRedisManager.java From dfactor with MIT License | 4 votes |
protected int initPool(DFRedisCfg cfg) throws Throwable{ lockRedisRead.lock(); try{ Integer existId = mapRedisId.get(cfg.strId); if(existId != null){ //pool exist return existId; } }finally{ lockRedisRead.unlock(); } // JedisPool pool = DFRedisUtil.createJedisPool( cfg.getHost(), cfg.getPort(), cfg.getAuth(), cfg.getMaxTotal(), cfg.getMaxIdle(), cfg.getMinIdle(), cfg.getConnTimeoutMilli(), cfg.getBorrowTimeoutMilli()); //test connection boolean testFail = false; Jedis conn = null; Throwable eOut = null; try{ conn = pool.getResource(); conn.ping(); }catch(Throwable e){ testFail = true; eOut = e; }finally{ if(conn != null){ conn.close(); } if(testFail && pool != null){ pool.close(); } } if(eOut != null){ throw eOut; } // RedisPoolWrap wrap = new RedisPoolWrap(pool, cfg.strId); lockRedisWrite.lock(); try{ int curId = redisIdCount; mapRedis.put(curId, wrap); mapRedisId.put(cfg.strId, curId); if(redisIdCount >= Integer.MAX_VALUE){ redisIdCount = 1; }else{ ++redisIdCount; } return curId; }finally{ lockRedisWrite.unlock(); } }
Example 4
Source File: MyTest.java From ehousechina with Apache License 2.0 | 4 votes |
@Test public void test1() { Snowflake s = SnowflakeUtil.getSnowflake(); JedisPoolConfig jedisPoolConfig = new JedisPoolConfig(); jedisPoolConfig.setMaxTotal(500); jedisPoolConfig.setMaxIdle(500); jedisPoolConfig.setMaxWaitMillis(-1); jedisPoolConfig.setTestOnBorrow(true); jedisPoolConfig.setTestOnReturn(true); JedisPool jedisPool = new JedisPool(jedisPoolConfig, "10.99.70.53", 32853); try { while (true) { i++; long id = s.next(); System.out.println(i + "----" + id); // pool.execute(new Runnable() { // @Override // public void run() { // i++; // Jedis jedis = jedisPool.getResource(); // long id = s.next(); // System.out.println(i+"----"+id); // long value = jedis.setnx(String.valueOf(id), ""); // if(value==0){ // System.out.println("1111111111111111111111"); // } // jedis.close(); } // }); // TimeUnit.NANOSECONDS.sleep(1); // } } catch (Exception e) { e.printStackTrace(); } finally { jedisPool.close(); } // long value = jedis.setnx("test", "test"); // System.out.println(value); /* * jedis.close(); jedisPool.close(); */ }