Redis 数据库连接池编写
2020-04-01 19:03
846 查看
Utils 类编写
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 (IOException e) { e.printStackTrace(); } //获取数据,设置到JedisPoolConfig中 JedisPoolConfig config = new JedisPoolConfig(); config.setMaxTotal(Integer.parseInt(pro.getProperty("maxTotal"))); config.setMaxIdle(Integer.parseInt(pro.getProperty("maxIdle"))); //初始化JedisPool jedisPool = new JedisPool(config,pro.getProperty("host"),Integer.parseInt(pro.getProperty("port"))); } /** * 获取连接方法 */ public static Jedis getJedis(){ return jedisPool.getResource(); } }
获取连接池工具类
//通过连接池工具类获取 Jedis jedis = JedisPoolUtils.getJedis();
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- DBCP开源数据库连接池的编写源码
- C3P0开源数据库连接池的编写源码
- 第三百五十七节,Python分布式爬虫打造搜索引擎Scrapy精讲—利用开源的scrapy-redis编写分布式爬虫代码
- spring boot初体验(五)集成Redis编写通用类
- linux之redis启动脚本编写v1.0
- Redis 和数据库连接池
- redis 主从配置(哨兵监控) 以及redis工具类编写
- 跨平台轻量级redis、ssdb代理服务器(C++ 11编写)
- 编写自己的jdbc数据库连接池
- shell编写redis启动脚本
- 编写Redis启停服务脚本
- 在做Redis集群的时候,如何在Linux编写批处理?
- 基于springboot+bootstrap+mysql+redis搭建一套完整的权限架构【四】【编写基础开发工具】
- 编写数据库连接池(一)
- 使用 acl 库编写高效的 C++ redis 客户端应用
- 编写Redis启停服务脚本
- SHELL编写redis启动脚本
- Redis入门和使用String类型编写计数器实例
- (转)使用异步Python 3.6和Redis编写快速应用程序
- 编写数据库连接池