| import redis.clients.jedis.Jedis; |
| import redis.clients.jedis.JedisPool; |
| import redis.clients.jedis.JedisPoolConfig; |
| |
| import java.io.InputStream; |
| import java.util.Properties; |
| |
| public class JedisUtils { |
| private static JedisPool jedispool; |
| static{ |
| InputStream input = JedisUtils.class.getClassLoader().getResourceAsStream("jedis.properties"); |
| Properties properties = new Properties(); |
| |
| try{ |
| properties.load(input); |
| System.out.println(properties); |
| }catch(Exception e){ |
| throw new RuntimeException(); |
| } |
| |
| 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")),5000,properties.getProperty("password")); |
| } |
| |
| * 获取连接方法 |
| */ |
| public static Jedis getJedis(){ |
| return jedispool.getResource(); |
| } |
| } |