JedisPoolUtil工具包
2021/12/3 23:18:22
本文主要是介绍JedisPoolUtil工具包,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
JedisPoolUtil的类
package cn.itcast.util; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; import redis.clients.jedis.JedisPoolConfig; import java.io.InputStream; import java.util.Properties; /** *JedisPoolUtils 工具类: * 加载配置文件,配置连接池的参数 * 提供获取连接方法 * */ public class JedisPoolUtils { private static JedisPool jedisPool; static { // 读取配置文件: InputStream is = JedisPoolUtils.class.getClassLoader().getResourceAsStream("jedis.properties"); // 创建properties对象: Properties pro = new Properties(); //关联文件: try { pro.load(is); }catch (Exception e){ e.printStackTrace(); } JedisPoolConfig config = new JedisPoolConfig(); config.setMaxIdle(Integer.parseInt(pro.getProperty("maxIdle"))); config.setMaxTotal(Integer.parseInt(pro.getProperty("maxTotal"))); // 初始化;;JedisPool jedisPool=new JedisPool(config,pro.getProperty("host"),Integer.parseInt(pro.getProperty("port"))); } public static Jedis getJedis(){ return jedisPool.getResource(); } }
所需要的配置文件:
host=localhost port=6379 maxTotal=50 maxIdle=10
这篇关于JedisPoolUtil工具包的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-09-21订单系统资料入门教程:轻松管理你的订单
- 2024-09-21Java部署资料:新手入门教程
- 2024-09-21Java部署资料:新手入门教程
- 2024-09-21Java订单系统资料:新手入门教程与实战指南
- 2024-09-21Java管理系统资料入门教程
- 2024-09-21从零开始学习Java监控系统资料
- 2024-09-21Java就业项目资料:新手入门的必备教程
- 2024-09-21Java全端资料:初学者指南
- 2024-09-21Java全栈资料入门教程及资源汇总
- 2024-09-21Java日志系统资料入门教程