jedis pool 是基于apache common pool 实现。所以在使用时我们需要导入Jedis 和apache common pool两个jar包
使用案例
JedisPool pool = new JedisPool();
for(int i = 0; i<100;++i){
Jedis jedis = pool.getResource();
System.out.println(jedis.get("key"));
jedis.close();
}
使用完之后必须close(),这样就会输出100次value。
如不使用完不close(),就只会输出8次value,因为使用完不还回去,连接池就被你独占了,默认连接池为8条线程,你可以有8个链接,所以只输出8次value.