package com.briup.util;
import java.util.ResourceBundle;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
public class JedisUtils {
public static JedisPool jedisPool;
static {
//ResourceBundle会查找classpath下的xxx.properties的文件,xxx是方法中指定的
ResourceBundle resourceBundle = ResourceBundle.getBundle("redis");
int maxTotal = Integer.parseInt(resourceBundle.getString("redis.pool.maxTotal"));
int maxIdle = Integer.parseInt(resourceBundle.getString("redis.pool.maxIdle"));
int maxWait = Integer.parseInt(resourceBundle.getString("redis.pool.maxWait"));
String ip = resourceBundle.getString("redis.ip");
int port = Integer.parseInt(resourceBundle.getString("redis.port"));
JedisPoolConfig config = new JedisPoolConfig();
// 设置最大连接数
config.setMaxTotal(maxTotal);
// 设置最大空闲数
config.setMaxIdle(maxIdle);
// 设置超时时间
config.setMaxWaitMillis(maxWait);
// 初始化连接池
jedisPool = new JedisPool(config, ip, port);
}
public static void set(Object key, Object value) {
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
jedis.set(SerializingUtils.serialize(key), SerializingUtils.serialize(value));
} catch (Exception e) {
e.printStackTrace();
}finally {
jedis.close();
}
}
public static Object get(Object key) {
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
byte[] keyBytes = SerializingUtils.serialize(key);
if(jedis.exists(keyBytes)){
return SerializingUtils.deserialize(jedis.get(keyBytes));
}
} catch (Exception e) {
e.printStackTrace();
}finally {
jedis.close();
}
return null;
}
public static void del(Object key) {
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
jedis.del(SerializingUtils.serialize(key));
} catch (Exception e) {
e.printStackTrace();
}finally {
jedis.close();
}
}
public static void clear() {
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
jedis.flushDB();
} catch (Exception e) {
e.printStackTrace();
}finally {
jedis.close();
}
}
public static int getSize() {
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
} catch (Exception e) {
e.printStackTrace();
}finally {
jedis.close();
}
return jedis.dbSize().intValue();
}
public static Jedis getResource(){
return jedisPool.getResource();
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
1.注意修改db.properties中的数据库配置信息,保持和自己的一致 2.建表语句在com.briup.sql包里面 3.运行项目之前,要先开启Redis服务器 4.register.jsp页面中可以测试ssm整体的框架搭建以及事务是否可以回滚 5.success.jsp页面中可以测试Redis是否配置成功,多次点击按钮查询观察select的执行情况 6.压缩包里有三个demo1,分别是mybatis二级缓存版、spring4.0版、spring3.0版。
资源推荐
资源详情
资源评论















收起资源包目录





































































































共 233 条
- 1
- 2
- 3
资源评论

- jaslou2017-11-06没有下载成功
- hongjiangye57212017-10-09有不同人不同

jeffrey_ding
- 粉丝: 89
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- SQl-MFC人事管理完整.doc
- maku-admin-Typescript资源
- 多普达仿苹果Iphone手机锁屏软件S2U2使用教程.doc
- 电力通信自动化信息安全漏洞及防范措施研究.docx
- 互联网+背景下大学生诚信教育体系建设探究.docx
- 企业门户网站的设计方案与实现.doc
- 网络安全现状及应对措施.docx
- 浅析PLC技术在电气工程自动化控制中的应用.docx
- ERP项目管理方法研究.doc
- 网络安全课程在线学习系统的设计.docx
- 合作学习在中职计算机教学管理中的应用.docx
- 串口通信(郭天祥).ppt
- 计算机网络技术学科的就业前景分析.docx
- 数据库课程设计题目汇总分析.doc
- 数据库课程方案设计书报告(医院管理系统).doc
- 试论智慧城市建设下广电网络发展的机遇与挑战.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
