最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

SpringMVC集成redis配置的多種實(shí)現(xiàn)方法

 更新時間:2021年03月29日 14:58:31   作者:Abdulaziz_Dev  
這篇文章主要介紹了SpringMVC集成redis配置的多種實(shí)現(xiàn)方法,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下

第一步:下載并安裝Redis(網(wǎng)上已經(jīng)有很多安裝教程在此不細(xì)講了)

第二步:pom文件引入jar包
在此需要注意Redis和jedis連接工廠版本
redsi:https://mvnrepository.com/artifact/org.springframework.data/spring-data-redis
jedis:https://mvnrepository.com/artifact/redis.clients/jedis

 <!-- redis -->
		<dependency> 
		 <groupId>org.springframework.data</groupId> 
		 <artifactId>spring-data-redis</artifactId> 
		 <version>1.7.2.RELEASE</version> 
		</dependency> 
		<dependency> 
		 <groupId>redis.clients</groupId> 
		 <artifactId>jedis</artifactId> 
		 <version>2.9.0</version> 
		</dependency>

第三步:配置redis.properties文件

# Redis Setting
# Redis默認(rèn)有16個庫,序號是0-15,默認(rèn)是選中的是0號數(shù)據(jù)庫
spring.redis.database=0 
# Redis服務(wù)器地址
spring.redis.host=127.0.0.1
# Redis服務(wù)器連接端口,默認(rèn)是6379
spring.redis.port=6379 
# Redis服務(wù)器連接密碼(默認(rèn)為空)
# spring.redis.password=你的密碼
# 連接池最大阻塞等待時間(使用負(fù)值表示沒有限制),根據(jù)實(shí)際情況修改
spring.redis.pool.maxWaitMillis=-1 
# 連接池中的最大空閑連接,根據(jù)實(shí)際情況修改
spring.redis.pool.maxIdle=8 
# 連接池中的最小空閑連接,根據(jù)實(shí)際情況修改
spring.redis.pool.minIdle=0 
# 連接超時時間(毫秒),根據(jù)實(shí)際情況修改
spring.redis.timeout=2000 

第四步:配置spring-redis-config.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cache="http://www.springframework.org/schema/cache"
  xmlns:context="http://www.springframework.org/schema/context"
  xmlns:redis="http://www.springframework.org/schema/redis" xmlns:tx="http://www.springframework.org/schema/tx"
  xsi:schemaLocation="http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-4.0.xsd
  http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
  http://www.springframework.org/schema/redis http://www.springframework.org/schema/redis/spring-redis-1.0.xsd
  http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
 
 <!-- 載入redis.properties,這里要特別注意,如果有多個properties文件,必須用逗號分開,不能寫成兩個 <context:property-placeholder/> -->
 <context:property-placeholder location="classpath:redis.properties" />
 
 <!-- 配置JedisPoolConfig連接池-->
 <bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig">
  <property name="maxIdle" value="${spring.redis.pool.maxIdle}"></property>
  <property name="minIdle" value="${spring.redis.pool.minIdle}"></property>
  <property name="maxWaitMillis" value="${spring.redis.pool.maxWaitMillis}"></property>
 </bean>
 
 <!-- 配置jedis連接工廠 -->
 <bean id="connectionFactory"
   class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
  <property name="poolConfig" ref="poolConfig"></property>
  <property name="hostName" value="${spring.redis.host}"></property>
  <property name="port" value="${spring.redis.port}"></property>
<!--   <property name="password" value="${spring.redis.password}"></property> -->
  <property name="database" value="${spring.redis.database}"></property>
  <property name="timeout" value="${spring.redis.timeout}"></property>
 </bean>
 
 <!-- 配置RedisTemplate -->
 <bean id="stringRedisSerializer" class="org.springframework.data.redis.serializer.StringRedisSerializer" />
 <bean id="cacheRedisTemplate" class="org.springframework.data.redis.core.RedisTemplate" >
  <property name="connectionFactory" ref="connectionFactory" />
  <property name="keySerializer" ref="stringRedisSerializer" />
  <property name="hashKeySerializer" ref="stringRedisSerializer" />
  <property name="valueSerializer" ref="stringRedisSerializer" />
  <property name="hashValueSerializer" ref="stringRedisSerializer" />
 </bean>
</beans>

第五步:spring集成spring-redis文件
方式一:在spring配置文件中加入:

<import resource="classpath:spring-redis-config.xml"/>

方式二:直接將spring-redis-config的東西寫到spring配置文件里。

spring集成Redis基本配置完成!

到此這篇關(guān)于SpringMVC集成redis配置的多種實(shí)現(xiàn)方法的文章就介紹到這了,更多相關(guān)SpringMVC集成redis配置內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • redis保存AtomicInteger對象踩坑及解決

    redis保存AtomicInteger對象踩坑及解決

    這篇文章主要介紹了redis保存AtomicInteger對象踩坑及解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-11-11
  • 利用Redis的有序集合實(shí)現(xiàn)排行榜功能實(shí)例代碼

    利用Redis的有序集合實(shí)現(xiàn)排行榜功能實(shí)例代碼

    這篇文章主要給大家介紹了關(guān)于如何利用Redis的有序集合實(shí)現(xiàn)排行榜功能的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者使用Redis具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-03-03
  • Redis異步隊列的實(shí)現(xiàn)及應(yīng)用場景

    Redis異步隊列的實(shí)現(xiàn)及應(yīng)用場景

    異步隊列是一種底層基于異步 I/O 模型的消息隊列,用于在分布式系統(tǒng)中進(jìn)行同步和異步的通訊和協(xié)作,本文主要介紹了Redis異步隊列的實(shí)現(xiàn)及應(yīng)用場景,感興趣的可以了解一下
    2023-12-12
  • Redis高并發(fā)緩存問題分析及解決過程

    Redis高并發(fā)緩存問題分析及解決過程

    文章總結(jié)了Redis緩存的六種常見問題及其解決方案:緩存穿透、緩存擊穿、緩存雪崩、熱點(diǎn)key重建優(yōu)化、緩存和數(shù)據(jù)庫雙寫不一致,以及Redis對過期key的三種清除策略,每種問題都提供了詳細(xì)的原因分析和具體的解決方案
    2025-01-01
  • redis緩存與數(shù)據(jù)庫一致性的問題及解決

    redis緩存與數(shù)據(jù)庫一致性的問題及解決

    這篇文章主要介紹了redis緩存與數(shù)據(jù)庫一致性的問題及解決,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-06-06
  • redis復(fù)制有可能碰到的問題匯總

    redis復(fù)制有可能碰到的問題匯總

    這篇文章主要介紹了redis復(fù)制有可能碰到的問題匯總,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-04-04
  • Redis源碼解析:集群手動故障轉(zhuǎn)移、從節(jié)點(diǎn)遷移詳解

    Redis源碼解析:集群手動故障轉(zhuǎn)移、從節(jié)點(diǎn)遷移詳解

    這篇文章主要介紹了Redis源碼解析:集群手動故障轉(zhuǎn)移、從節(jié)點(diǎn)遷移的相關(guān)內(nèi)容,涉及通過集群定時器函數(shù)clusterCron實(shí)現(xiàn)從節(jié)點(diǎn)遷移等知識,具有一定參考價值,需要的朋友可以了解。
    2017-10-10
  • Ubuntu系統(tǒng)中Redis的安裝步驟及服務(wù)配置詳解

    Ubuntu系統(tǒng)中Redis的安裝步驟及服務(wù)配置詳解

    本文主要記錄了Ubuntu服務(wù)器中Redis服務(wù)的安裝使用,包括apt安裝和解壓縮編譯安裝兩種方式,并對安裝過程中可能出現(xiàn)的問題、解決方案進(jìn)行說明,以及在手動安裝時,服務(wù)器如何添加自定義服務(wù)的問題,需要的朋友可以參考下
    2024-12-12
  • Redis多種內(nèi)存淘汰策略及配置技巧分享

    Redis多種內(nèi)存淘汰策略及配置技巧分享

    本文介紹了 Redis 內(nèi)存滿時的淘汰機(jī)制,包括內(nèi)存淘汰機(jī)制的概念,Redis 提供的 8 種淘汰策略(如 noeviction、volatile-lru 等)及其適用場景,還講解了如何配置淘汰機(jī)制,通過合理配置可提高緩存效率和系統(tǒng)性能,需要的朋友可以參考下
    2025-01-01
  • 一文詳解如何停止/重啟/啟動Redis服務(wù)

    一文詳解如何停止/重啟/啟動Redis服務(wù)

    Redis是當(dāng)前比較熱門的NOSQL系統(tǒng)之一,它是一個key-value存儲系統(tǒng),這篇文章主要給大家介紹了關(guān)于如何停止/重啟/啟動Redis服務(wù)的相關(guān)資料,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2024-03-03

最新評論

邵武市| 蒙阴县| 卢湾区| 张掖市| 雅安市| 霍邱县| 安龙县| 成安县| 沾化县| 山东省| 东方市| 罗甸县| 宝鸡市| 麻栗坡县| 巍山| 安庆市| 洛阳市| 阳新县| 怀化市| 内乡县| 新泰市| 日照市| 遂宁市| 鱼台县| 公安县| 虞城县| 海伦市| 正阳县| 彭州市| 博罗县| 高尔夫| 集贤县| 谷城县| 田林县| 云林县| 太湖县| 镇雄县| 鸡东县| 勃利县| 册亨县| 玛曲县|