国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > Java > 正文

ssm開發(fā)使用redis作為緩存的使用步驟

2024-07-14 08:42:44
字體:
供稿:網(wǎng)友

1、關(guān)于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數(shù)據(jù)源--> <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數(shù)據(jù)庫的管理

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相關(guān)依賴

<!-- redis相關(guān)依賴jedis -->   <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>2.6.1</version>

 以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持VeVb武林網(wǎng)。


注:相關(guān)教程知識閱讀請移步到JAVA教程頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 芦溪县| 富阳市| 灵武市| 汉川市| 桦南县| 吴川市| 佛教| 金湖县| 林州市| 灌阳县| 马尔康县| 武强县| 额尔古纳市| 永清县| 怀来县| 改则县| 新野县| 清水河县| 武安市| 德保县| 囊谦县| 招远市| 克什克腾旗| 阜新| 枣阳市| 沾益县| 买车| 扎赉特旗| 临海市| 固镇县| 江都市| 横峰县| 乐清市| 鹤岗市| 九台市| 山阴县| 偃师市| 托里县| 六盘水市| 元氏县| 皋兰县|