private static final String redisPropertiesFileName = "redis.properties";
static {
inputStream = JedisPoolImpl.class.getResourceAsStream("/"+redisPropertiesFileName);
Properties pro = new Properties();
try {
pro.load(inputStream);
JedisPoolConfig config = new JedisPoolConfig();
config.setMaxTotal(Integer.parseInt(pro.getProperty("redis.pool.maxTotal")));//setMaxActive
config.setMaxIdle(Integer.parseInt(pro.getProperty("redis.pool.maxIdle")));
config.setMaxWaitMillis(Integer.parseInt(pro.getProperty("redis.pool.maxWaitMillis")));//setMaxWait
config.setTestOnBorrow(true);
String ip = pro.getProperty("redis.host");//读取配置文件
int port = Integer.parseInt(pro.getProperty("redis.port"));//读取配置文件
String password = pro.getProperty("redis.password");
int timeOut = Integer.parseInt(pro.getProperty("redis.timeout"));
if (StringUtils.isNotBlank(ip) && port > 1000) {
pool = new JedisPool(config, ip,
port, timeOut,password);
LOG.info("jedisPool ready on : host " + ip + " port "
+ port + " ...");
} else {
LOG.error("jedisPool init false ...");
}
} catch (Exception e) {
LOG.error("jedisPool init false ...");
}
}
java读取properties文件
最新推荐文章于 2024-09-27 21:51:44 发布