ssm开发使用redis作为缓存,使用步骤
来源:互联网 发布:淘宝开放平台 什么 编辑:程序博客网 时间:2024/06/05 11:38
转自:https://www.cnblogs.com/wiseroll/p/7258863.html
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>
package org.slsale.common;import redis.clients.jedis.Jedis;import redis.clients.jedis.JedisPool;/** * jedisAPI */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); } }}
阅读全文
0 0
- ssm开发使用redis作为缓存,使用步骤
- 使用redis作为缓存
- 使用redis作为缓存
- 使用Redis作为LRU缓存
- 使用Redis作为LRU缓存
- 使用Redis作为缓存2
- 使用Redis作为LRU缓存
- 使用Redis作为LRU缓存
- SSM项目中使用Redis缓存
- Redis作为MySQL缓存服务器的使用
- nodejs使用redis作为缓存介质,封装缓存类
- REDIS学习(3.2)spring boot 使用redis作为缓存
- iReport 使用JavaBean作为数据源开发报表(SSM)
- 在.Net项目中使用Redis作为缓存服务
- [Shiro入门](一)使用Redis作为缓存管理器
- mybatis使用redis作为自定义缓存的配置
- (spring-data-redis)SSM框架下使用redis作为mybatis的二级缓存
- redis结合ssm框架中的使用,以AOP原理做一个redis缓存管理
- SLF4J: Class path contains multiple SLF4J bindings
- [jzoj]3479. 【NOIP2013模拟联考9】工作安排(work)
- 【Scikit-Learn 中文文档】数据集加载工具
- 设计模式-面向对象设计核心
- POJ-3669
- ssm开发使用redis作为缓存,使用步骤
- 1.2指令集体系结构分类
- Java中关于volatile关键字的一些总结
- 减少Android Studio应用项目体积的办法
- 【Scikit-Learn 中文文档】大规模计算的策略: 更大量的数据
- E: Sub-process /usr/bin/dpkg returned an error code (1) 解决方案
- Mysql学习(一)
- 【Scikit-Learn 中文文档】预测延迟 / 预测吞吐量 / 技巧和窍门
- 【Scikit-Learn 中文文档】使用 scikit-learn 介绍机器学习