首页 > 其他 > 详细

2020.05.09 JedisPoolUtils

时间:2020-05-10 00:20:44      阅读:80      评论:0      收藏:0      [点我收藏+]
package com.aojie.jedis.util;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
* @author aojie
* @fuction JedisPool工具类
* @create 2020-05-09 20:11
*/
public class JedisPoolUtils {
private static JedisPool jedisPool;
/**
* 获取连接的方法
*/
static {
//读取配置文件
InputStream resourceAsStream = JedisPoolUtils.class.getClassLoader().getResourceAsStream("jedis.properties");
Properties properties = new Properties();
try {
properties.load(resourceAsStream);
} catch (IOException e) {
e.printStackTrace();
}
//获取数据 设置到jedispoolconfig中
JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
jedisPoolConfig.setMaxTotal(Integer.parseInt(properties.getProperty("maxTotal")));
jedisPoolConfig.setMaxIdle(Integer.parseInt(properties.getProperty("maxIdle")));
//初始化连接池对象
jedisPool = new JedisPool(jedisPoolConfig, properties.getProperty("host"),Integer.parseInt(properties.getProperty("port")));
}
public static Jedis getJedis(){
return jedisPool.getResource();
}

}

2020.05.09 JedisPoolUtils

原文:https://www.cnblogs.com/aojie/p/12860537.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!