package tools;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;public class JedisPoolUtils { /
package tools;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;public class JedisPoolUtils { // 连接池 private static JedisPool jedisPool; static { // 字节输出流 InputStream resourceAsStream = JedisPoolUtils.class.getClassLoader().getResourceAsStream("tools/jedisConfig.properties"); // 配置集合 Properties properties = new Properties(); try { // 集合加载流数据 properties.load(resourceAsStream); } catch (IOException e) { e.printStackTrace(); } // 连接池配置 JedisPoolConfig jedisPoolConfig = new JedisPoolConfig(); String maxTotal = properties.getProperty("maxTotal"); int intTotal = Integer.parseInt(maxTotal); jedisPoolConfig.setMaxTotal(intTotal); String maxIdle = properties.getProperty("maxIdle"); int intIdle = Integer.parseInt(maxIdle); jedisPoolConfig.setMaxIdle(intIdle); // 连接池创建 jedisPool = new JedisPool( jedisPoolConfig, properties.getProperty("host"), Integer.parseInt(properties.getProperty("port")) ); } public static Jedis getJedis() { // 返回一个连接 return jedisPool.getResource(); }}