package com.itheima.jedis;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
public class JedisPoolUtils {
private static JedisPool pool = null;
static {
//加载配置文件
InputStream inputStream = JedisPoolUtils.class.getClassLoader().getResourceAsStream("redis.properties");
Properties pro=new Properties();
try {
pro.load(inputStream);
} catch (IOException e) {
e.printStackTrace();
}
JedisPoolConfig poolConfig = new JedisPoolConfig();
poolConfig.setMaxIdle(Integer.parseInt(pro.get("redis.maxIdle").toString()));
poolConfig.setMinIdle(Integer.parseInt(pro.get("redis.minIdle").toString()));
poolConfig.setMaxTotal(Integer.parseInt(pro.get("redis.maxTotal").toString()));
JedisPool pool = new JedisPool(poolConfig,pro.getProperty("redis.url"), Integer.parseInt(pro.get("redis.port").toString()));
}
// 获得jedis资源的方法
public static Jedis getJedis() {
return pool.getResource();
}
public static void main(String[] args) {
Jedis jedis=getJedis();
System.out.println("xxx");
}
}
-----------------------------------------------------
redis.maxIdle=30
redis.minIdle=10
reids.maxTotal=100
reids.url=192.168.186.131
redis.port=6379