-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
86 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.mmall.common; | ||
|
||
import com.mmall.util.PropertiesUtil; | ||
import redis.clients.jedis.JedisPool; | ||
|
||
public class RedisPool { | ||
private static JedisPool pool;//jedis连接池 | ||
private static Integer maxTotal = Integer.parseInt(PropertiesUtil.getProperty("redis.max.total","20"));//最大连接数 | ||
private static Integer maxIdle = Integer.parseInt(PropertiesUtil.getProperty("redis.max.idle","20"));//在jedispool中最大的idle状态(空闲的)的jedis实例的个数 | ||
private static Integer minIdle = Integer.parseInt(PropertiesUtil.getProperty("redis.min.idle","20"));//在jedispool中最小的idle状态(空闲的)的jedis实例的个数 | ||
private static Boolean testOnBorrow = Boolean.parseBoolean(PropertiesUtil.getProperty("redis.test.borrow","true"));//在borrow一个jedis实例的时候,是否要进行验证操作,如果赋值true, 则得到的jedis实例肯定是可以用的。 | ||
private static Boolean testOnReturn = Boolean.parseBoolean(PropertiesUtil.getProperty("redis.test.return","true"));//在return一个jedis实例的时候,是否要进行验证操作,如果赋值true, 则放回jedispool的jedis实例肯定是可以用的。 | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.mmall.util; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.Properties; | ||
|
||
/** | ||
* Created by geely | ||
*/ | ||
public class PropertiesUtil { | ||
|
||
private static Logger logger = LoggerFactory.getLogger(PropertiesUtil.class); | ||
|
||
private static Properties props; | ||
|
||
static { | ||
String fileName = "mmall.properties"; | ||
props = new Properties(); | ||
try { | ||
props.load(new InputStreamReader(PropertiesUtil.class.getClassLoader().getResourceAsStream(fileName),"UTF-8")); | ||
} catch (IOException e) { | ||
logger.error("配置文件读取异常",e); | ||
} | ||
} | ||
|
||
public static String getProperty(String key){ | ||
String value = props.getProperty(key.trim()); | ||
if(StringUtils.isBlank(value)){ | ||
return null; | ||
} | ||
return value.trim(); | ||
} | ||
|
||
public static String getProperty(String key,String defaultValue){ | ||
|
||
String value = props.getProperty(key.trim()); | ||
if(StringUtils.isBlank(value)){ | ||
value = defaultValue; | ||
} | ||
return value.trim(); | ||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters