ssm开发使用redis作为缓存,使用步骤
1、关于spring配置文件中对于redis的配置
<!-- redis配置 -->
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
<!-- <property name="maxActive" value="90"/> -->
<property name="maxIdle" value="5"/>
<!-- <property name="maxWait" value="1000"/> -->
<property name="testOnBorrow" value="true"/>
</bean>
<!--配置redis数据源-->
<bean id="jedisPool" class="redis.clients.jedis.JedisPool" destroy-method="destroy">
<constructor-arg ref="jedisPoolConfig"/>
<constructor-arg value="192.168.21.195"/>
<constructor-arg value="6379"/>
</bean>
<!--配置自定义的RedisAPI工具类-->
<bean id="redisAPI" class="org.slsale.common.RedisAPI">
<property name="jedisPool" ref="jedisPool"/>
</bean>
2、配置自定义的RedisAPI,对redis数据库的管理
package org.slsale.common; import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool; /**
* jedisAPI
* @author luzhewu
*
*/
public class RedisAPI {
public JedisPool jedisPool;// redis连接池对象 public JedisPool getJedisPool() {
return jedisPool;
} public void setJedisPool(JedisPool jedisPool) {
this.jedisPool = jedisPool;
} /**
* set key and value tp redis
* @param key
* @param value
* @return
*/
public boolean set(String key, String value) {
Jedis jedis = null;
try {
jedis = jedisPool.getResource();// 获取jedis对象
jedis.set(key, value);
return true;
} catch (Exception e) {
e.printStackTrace();
} finally {
// 返还到连接池
returnResource(jedisPool, jedis);
}
return false;
} /**
* 判断某个key是否存在
* @param key
* @return
*/
public boolean exist(String key) {
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
return jedis.exists(key);
} catch (Exception e) {
e.printStackTrace();
} finally {
// 返还到连接池
returnResource(jedisPool, jedis);
}
return false;
} /**
* 通过key获取value
* @param key
* @return
*/
public String get(String key) {
String value = null;
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
value = jedis.get(key);
} catch (Exception e) {
e.printStackTrace();
} finally {
// 返还到连接池
returnResource(jedisPool, jedis);
}
return value;
} /**
* 返还到连接池
* @param jedisPool
* @param jedis
*/
public static void returnResource(JedisPool jedisPool, Jedis jedis) {
if (jedis != null) {
jedisPool.returnResource(jedis);
}
}
}
3、redis相关依赖
<!-- redis相关依赖jedis -->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.6.1</version>
ssm开发使用redis作为缓存,使用步骤的更多相关文章
- spring boot-16.使用redis做缓存
spring boot 自动配置了多种 缓存管理器,按照下面的顺序查找,如果容器中有相应的组件,则使用相应的缓存管理器. Generic JCache (JSR-107) EhCache 2.x Ha ...
- 开发步骤Dubbo、spring mvc、springboot、SSM开发步骤
一.Dubbo开发步骤: 链接:https://pan.baidu.com/s/1pMPO1kf 密码:9zaa 第一: 1.创建consumer工程2.在pom.xml文件下添加配置3.添加appl ...
- Spring Boot + Mybatis + Redis二级缓存开发指南
Spring Boot + Mybatis + Redis二级缓存开发指南 背景 Spring-Boot因其提供了各种开箱即用的插件,使得它成为了当今最为主流的Java Web开发框架之一.Mybat ...
- Spring Boot 整合 Redis 实现缓存操作
摘要: 原创出处 www.bysocket.com 「泥瓦匠BYSocket 」欢迎转载,保留摘要,谢谢! 『 产品没有价值,开发团队再优秀也无济于事 – <启示录> 』 本文提纲 ...
- 知乎技术分享:从单机到2000万QPS并发的Redis高性能缓存实践之路
本文来自知乎官方技术团队的“知乎技术专栏”,感谢原作者陈鹏的无私分享. 1.引言 知乎存储平台团队基于开源Redis 组件打造的知乎 Redis 平台,经过不断的研发迭代,目前已经形成了一整套完整自动 ...
- spring配置redis注解缓存
前几天在spring整合Redis的时候使用了手动的方式,也就是可以手动的向redis添加缓存与清除缓存,参考:http://www.cnblogs.com/qlqwjy/p/8562703.html ...
- c#实例化继承类,必须对被继承类的程序集做引用 .net core Redis分布式缓存客户端实现逻辑分析及示例demo 数据库笔记之索引和事务 centos 7下安装python 3.6笔记 你大波哥~ C#开源框架(转载) JSON C# Class Generator ---由json字符串生成C#实体类的工具
c#实例化继承类,必须对被继承类的程序集做引用 0x00 问题 类型“Model.NewModel”在未被引用的程序集中定义.必须添加对程序集“Model, Version=1.0.0.0, Cu ...
- Django使用Redis进行缓存详细最全流程
背景和意义服务器数据非经常更新.若每次都从硬盘读取一次,浪费服务器资源.拖慢响应速度.而且数据更新频率较高,服务器负担比较大.若保存到数据库,还需要额外建立一张对应的表存储数据.在Django中建立表 ...
- 四、NOSQL之Redis持久化缓存服务基础实战第三部
1.NOSQL的理解 NOSQL是不仅仅是SQL,说的就是sql的补充,但是不能替代SQL. nosql库:memcached.memcachedb.redis 2.redis 简介 Redis是一个 ...
随机推荐
- 使用grunt-init自动创建gruntfile.js和package.json文件
使用grunt-init可以自动创建gruntfile.js和package.json文件.下面说一下过程: 1.全局安装grunt-init npm install -g grunt-init 2. ...
- 关于Makefile,Makefile.in,Makefile.am,Configure功能及相互关系的问题
makefile写法 在 Unix 上写程式的人大概都碰过 Makefile,尤其是用 C 来开发程式的人.用 make来开发和编译程式的确很方便,可是要写出一个 Makefile就不简单了.偏偏介绍 ...
- Leetcode题解(十五)
42.Trapping Rain Water 题目 这道题目参考http://www.cnblogs.com/felixfang/p/3713197.html 观察下就可以发现被水填满后的形状是先升后 ...
- K - Kia's Calculation (贪心)
Kia's Calculation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- Building roads
Building roads Time Limit: 10000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...
- 关于jQuery.click()函数
最近接手了前同事的项目,关于使用线程控制实现代码热插拔功能! 在线程中,使用了ChatWebSocketHandler,与前台进行实时交互,今天我拿到需求是这样的,结合chatWebSocketHan ...
- Pandas常用函数入门
一.Pandas Python Data Analysis Library或Pandas是基于NumPy的一种工具,该工具是为了解决数据分析任务而创建的.Pandas纳入了大量库和一些标准的数据模型, ...
- python3 xpath数据获取案例
import requestsfrom retrying import retryfrom lxml import etreeimport json class DaCheng(object): de ...
- 【Tesseract】Tesseract API在VS 2013中的配置以及调用
想要在VS中使用Tesseract库,必须使用经过相对应的VS版本编译过的dll以及lib.比如在VS 2013中,就必须使用在VS 2013中编译过的Tesseract库. 这里我给出经过VS 20 ...
- 免费好用的阿里云云盾证书服务(https证书)申请步骤
推荐一个免费的阿里云产品:云盾证书(https证书) 为了能让非专业人士看懂,同样尽量用直白的话,一般来说:当你个人需要建立网站,或者公司要建立官网.商城,通常需要先购买服务器或云主机,虚拟空间,然后 ...