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版。
资源推荐
资源详情
资源评论
收起资源包目录
SSM+Redis项目整合 (233个子文件)
JedisUtils.class 3KB
User.class 2KB
User.class 2KB
User.class 2KB
UserController.class 2KB
UserController.class 2KB
UserController.class 2KB
SerializingUtils.class 2KB
MybatisRedisCache.class 2KB
UserServiceImpl.class 1KB
UserServiceImpl.class 1KB
DateJsonSerializer.class 1KB
DateJsonSerializer.class 1KB
DateJsonSerializer.class 1KB
UserServiceImpl.class 1KB
IUserService.class 413B
IUserService.class 413B
IUserService.class 413B
IUserDao.class 334B
IUserDao.class 334B
IUserDao.class 334B
.classpath 661B
.classpath 661B
.classpath 661B
org.eclipse.wst.common.component 485B
org.eclipse.wst.common.component 483B
org.eclipse.wst.common.component 483B
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.jsdt.ui.superType.container 49B
aspectjweaver.jar 1.67MB
aspectjweaver.jar 1.67MB
aspectjweaver.jar 1.67MB
ojdbc14.jar 1.48MB
ojdbc14.jar 1.48MB
ojdbc14.jar 1.48MB
mybatis-3.3.0.jar 1.35MB
mybatis-3.3.0.jar 1.35MB
mybatis-3.3.0.jar 1.35MB
jackson-databind-2.8.5.jar 1.18MB
jackson-databind-2.8.5.jar 1.18MB
jackson-databind-2.8.5.jar 1.18MB
spring-context-4.3.3.RELEASE.jar 1.08MB
spring-data-redis-1.7.5.RELEASE.jar 1.07MB
spring-core-4.3.3.RELEASE.jar 1.06MB
spring-webmvc-4.3.3.RELEASE.jar 892KB
spring-core-3.2.4.RELEASE.jar 849KB
spring-core-3.2.4.RELEASE.jar 849KB
spring-context-3.2.4.RELEASE.jar 843KB
spring-context-3.2.4.RELEASE.jar 843KB
spring-web-4.3.3.RELEASE.jar 794KB
spring-beans-4.3.3.RELEASE.jar 743KB
spring-data-redis-1.6.2.RELEASE.jar 683KB
spring-webmvc-3.2.4.RELEASE.jar 622KB
spring-webmvc-3.2.4.RELEASE.jar 622KB
spring-web-3.2.4.RELEASE.jar 611KB
spring-web-3.2.4.RELEASE.jar 611KB
spring-beans-3.2.4.RELEASE.jar 594KB
spring-beans-3.2.4.RELEASE.jar 594KB
jedis-2.9.0.jar 541KB
jedis-2.9.0.jar 541KB
log4j-1.2.17.jar 478KB
log4j-1.2.17.jar 478KB
log4j-1.2.17.jar 478KB
spring-jdbc-4.3.3.RELEASE.jar 416KB
spring-jdbc-3.2.4.RELEASE.jar 396KB
spring-jdbc-3.2.4.RELEASE.jar 396KB
standard.jar 384KB
standard.jar 384KB
standard.jar 384KB
spring-aop-4.3.3.RELEASE.jar 371KB
spring-aop-3.2.4.RELEASE.jar 328KB
spring-aop-3.2.4.RELEASE.jar 328KB
jedis-2.6.2.jar 323KB
dom4j-1.6.1.jar 307KB
dom4j-1.6.1.jar 307KB
jackson-core-2.8.5.jar 274KB
jackson-core-2.8.5.jar 274KB
jackson-core-2.8.5.jar 274KB
spring-tx-4.3.3.RELEASE.jar 261KB
spring-expression-4.3.3.RELEASE.jar 258KB
spring-tx-3.2.4.RELEASE.jar 237KB
spring-tx-3.2.4.RELEASE.jar 237KB
spring-expression-3.2.4.RELEASE.jar 192KB
spring-expression-3.2.4.RELEASE.jar 192KB
spring-context-support-4.3.3.RELEASE.jar 183KB
commons-dbcp-1.4.jar 157KB
commons-dbcp-1.4.jar 157KB
commons-dbcp-1.4.jar 157KB
spring-context-support-3.2.4.RELEASE.jar 125KB
spring-context-support-3.2.4.RELEASE.jar 125KB
aspectjrt.jar 113KB
aspectjrt.jar 113KB
commons-pool2-2.4.2.jar 109KB
commons-pool2-2.4.2.jar 109KB
commons-pool2-2.4.2.jar 109KB
commons-pool.jar 61KB
commons-pool.jar 61KB
commons-pool.jar 61KB
commons-logging-1.2.jar 60KB
共 233 条
- 1
- 2
- 3
资源评论
- jaslou2017-11-06没有下载成功
- hongjiangye57212017-10-09有不同人不同
jeffrey_ding
- 粉丝: 89
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 冯璐阳 42105650—祝福.docx
- 基于多种算法及改进算法实现的移动机器人路径规划matlab源码(含A星算法+PRM+RRT的改进等).zip
- 布里斯托尔纸细分市场、总体规模、先进性、市占率行业分析报告2024年.docx
- Obi绳子插件,好用的很 6.5.4版本
- openjfx-22.0.1-windows-x64-bin-sdk.zip
- 基于ros和stm32f1的小车代码(含串口通信)+项目说明.zip
- 人体姿态估计-基于Tensorflow实现的人体姿态估计算法-附项目源码-优质项目分享.zip
- java实现所有算法大全
- JDBC DAO模式 (复习)
- Proteus仿真AT89C51电子密码锁
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功