redis工具类
package jedis;
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 JedisPoolUtil {
private static JedisPool jedisPool;
static{
InputStream in = JedisPoolUtil.class.getClassLoader().getResourceAsStream("jedis.properties");
Properties properties = new Properties();
try {
properties.load(in);
} catch (IOException e) {
e.printStackTrace();
}
JedisPoolConfig config = new JedisPoolConfig();
config.setMaxIdle(Integer.parseInt(properties.getProperty("maxTotal")));
config.setMaxIdle(Integer.parseInt(properties.getProperty("maxIdle")));
jedisPool = new JedisPool(config,properties.getProperty("host"), Integer.parseInt(properties.getProperty("port")));
}
public static Jedis getJedis(){
return jedisPool.getResource();
}
}
jedis.properties
host=127.0.0.1
port=6379
maxTotal=50
maxIdle=10