标签:nts private 文件 stat java load 配置文件 取数据 family
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();
}
}
标签:nts private 文件 stat java load 配置文件 取数据 family
原文地址:https://www.cnblogs.com/aojie/p/12860537.html