JedisPool工具类
来源:互联网 发布:物流软件定制开发 编辑:程序博客网 时间:2024/06/01 09:48
public class JedisPoolUtils {
private static JedisPool pool = null;
static{
//加载配置文件
InputStream in = JedisPoolUtils.class.getClassLoader().getResourceAsStream("redis.properties");
Properties pro = new Properties();
try {
pro.load(in);
} catch (IOException e) {
e.printStackTrace();
}
//获得池子对象(redis数据库)
JedisPoolConfig poolConfig = new JedisPoolConfig();
poolConfig.setMaxIdle(Integer.parseInt(pro.get("redis.maxIdle").toString()));//最大闲置个数
poolConfig.setMinIdle(Integer.parseInt(pro.get("redis.minIdle").toString()));//最小闲置个数
poolConfig.setMaxTotal(Integer.parseInt(pro.get("redis.maxTotal").toString()));//最大连接数
pool = new JedisPool(poolConfig,pro.getProperty("redis.url") , Integer.parseInt(pro.get("redis.port").toString()));
}
//获得jedis资源的方法
public static Jedis getJedis(){
return pool.getResource();
}
public static void main(String[] args) {
Jedis jedis = getJedis();
System.out.println(jedis.get("xxx"));
}
}
private static JedisPool pool = null;
static{
//加载配置文件
InputStream in = JedisPoolUtils.class.getClassLoader().getResourceAsStream("redis.properties");
Properties pro = new Properties();
try {
pro.load(in);
} catch (IOException e) {
e.printStackTrace();
}
//获得池子对象(redis数据库)
JedisPoolConfig poolConfig = new JedisPoolConfig();
poolConfig.setMaxIdle(Integer.parseInt(pro.get("redis.maxIdle").toString()));//最大闲置个数
poolConfig.setMinIdle(Integer.parseInt(pro.get("redis.minIdle").toString()));//最小闲置个数
poolConfig.setMaxTotal(Integer.parseInt(pro.get("redis.maxTotal").toString()));//最大连接数
pool = new JedisPool(poolConfig,pro.getProperty("redis.url") , Integer.parseInt(pro.get("redis.port").toString()));
}
//获得jedis资源的方法
public static Jedis getJedis(){
return pool.getResource();
}
public static void main(String[] args) {
Jedis jedis = getJedis();
System.out.println(jedis.get("xxx"));
}
}
阅读全文
0 0
- JedisPool工具类
- jedisPool
- JedisPool
- JedisPool
- Redis工具类,使用JedisPool,并设置jedis连接池的参数
- JedisPool介绍
- JedisPool分析
- JedisPool介绍
- JedisPool介绍
- JedisPool配置参数解析
- JedisPool以及参数适用
- JedisPool高并发
- redis配置jedisPool参数
- JedisPool.returnResource()遭弃用
- jedisPool相关参数说明
- JedisPool的配置参数
- redis-Jedispool学习
- JedisPool资源池优化
- javaScript深入学习[3]
- 并查集(1)梳理
- 使用kaldi进行特征提取时的问题记录
- 欢迎使用CSDN-markdown编辑器
- DenseNet
- JedisPool工具类
- gdb等待进程启动后调试
- WPF 实现简单的跑马灯
- 1007. 素数对猜想 (20)
- 二维码的扩展
- caffe在编译时注意事项
- 为什么L1正则项会产生稀疏解
- Spring AOP中pointcut expression表达式解析
- Go实战--golang中获取公网ip、查看内网ip、检测ip类型、校验ip区间、ip地址string和int转换、根据ip判断地区国家运营商等