Jedis和其连接池pool的工具类编写

1,maven需要依赖jar包
maven依赖自带 commons-pool
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();
    }

}

猜你喜欢

转载自blog.csdn.net/phcla/article/details/115447785