package com.itheima.util; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; import redis.clients.jedis.JedisPoolConfig; import java.util.ResourceBundle; public class JedisUtils { private static int maxTotal; private static int maxIdel; private static String host; private static int port; private static JedisPoolConfig jpc; private static JedisPool jp; static { ResourceBundle bundle = ResourceBundle.getBundle("redis"); maxTotal = Integer.parseInt(bundle.getString("redis.maxTotal")); maxIdel = Integer.parseInt(bundle.getString("redis.maxIdel")); host = bundle.getString("redis.host"); port = Integer.parseInt(bundle.getString("redis.port")); //Jedis连接池配置 jpc = new JedisPoolConfig(); jpc.setMaxTotal(maxTotal); jpc.setMaxIdle(maxIdel); jp = new JedisPool(jpc,host,port); } public static Jedis getJedis(){ return jp.getResource(); } }
redis.maxTotal=50 redis.maxIdel=10 redis.host=192.168.0.10 redis.port=6379
redis.properties
标签:jpc,redis,private,static,Jedis,port From: https://www.cnblogs.com/wscp/p/16855959.html