-
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
1 parent
f5d827a
commit fa04062
Showing
8 changed files
with
45 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package RedisConnection; | ||
|
||
import java.util.ResourceBundle; | ||
|
||
import redis.clients.jedis.Jedis; | ||
import redis.clients.jedis.JedisPool; | ||
import redis.clients.jedis.JedisPoolConfig; | ||
|
||
public class RedisUtils { | ||
private static JedisPool pool = null; | ||
private static int maxIdle; | ||
private static int minIdle; | ||
private static int maxTotal; | ||
private static String url; | ||
private static int port; | ||
|
||
|
||
static { | ||
//1.获取配置文件 | ||
ResourceBundle bundle = ResourceBundle.getBundle("redis"); | ||
maxIdle = Integer.parseInt(bundle.getString("maxIdle")) ; | ||
minIdle = Integer.parseInt(bundle.getString("minIdle")) ; | ||
maxTotal = Integer.parseInt(bundle.getString("maxTotal")) ; | ||
url = bundle.getString("url"); | ||
port = Integer.parseInt(bundle.getString("port")) ; | ||
//2.创建池子的配置 | ||
JedisPoolConfig config = new JedisPoolConfig(); | ||
config.setMaxIdle(maxIdle); //最大闲置个数 | ||
config.setMinIdle(minIdle); //最小闲置个数 | ||
config.setMaxTotal(maxTotal); //最大连接个数 | ||
|
||
//3.创建连接池对象 | ||
pool = new JedisPool(config,url, port); | ||
} | ||
|
||
//实现jedis方法 | ||
public static Jedis getJedis() { | ||
return pool.getResource(); | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,5 @@ | ||
maxIdle=30 | ||
minIdle=10 | ||
maxTotal=100 | ||
url=10.6.228.4 | ||
port=6379 |