1,maven需要依赖jar包
2,写工具类
public class JedisUtlis {
static JedisPool jedisPool;
static {
ResourceBundle bundle = ResourceBundle.getBundle("JedisPool");
JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
jedisPoolConfig.setMaxIdle(Integer.parseInt(bundle.getString("MaxIdle")));
jedisPoolConfig.setMaxTotal(Integer.parseInt(bundle.getString("MaxTotal")));
jedisPool = new JedisPool(jedisPoolConfig,bundle.getString("host"), Integer.parseInt(bundle.getString("port")));
}
/**
* 获取jedis
* @return
*/
public static Jedis getJedis(){
Jedis resource = jedisPool.getResource();
return resource;
}
public static void closeJedis(Jedis jedis){
jedis.close();
}
}