本文,講解 Spring Boot 如何集成 Redis Cache,實現緩存。javascript
博客地址:blog.720ui.com/java
在閱讀「Spring Boot 揭祕與實戰(二) 數據緩存篇 - 快速入門」後,對 Spring Boot 集成緩存機制有必定了解後,咱們來了解下 Redis Cache 的使用。git
Redis Cache 有很是豐富的使用場景,若是有興趣的話,能夠閱讀這篇文章「Redis實戰(五) 聊聊Redis使用場景」。github
在 Spring Boot 中集成 Redis Cache 很是容易,只須要兩個步驟。redis
首先,在 pom.xml 中增長Redis 依賴。spring
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-redis</artifactId>
</dependency>複製代碼
第二步,在 src/main/resources/application.properties 中配置數據源信息。緩存
spring.redis.host=localhost
spring.redis.port=6379
spring.redis.password=
spring.redis.database=1
spring.redis.pool.max-active=8
spring.redis.pool.max-wait=-1
spring.redis.pool.max-idle=500
spring.redis.pool.min-idle=0
spring.redis.timeout=0複製代碼
運行起來,控制檯打印的日誌信息,說明已是 Redis Cache 實例,說明 Redis Cache 開啓成功了。springboot
Bean 'cacheManager' of type [class org.springframework.data.redis.cache.RedisCacheManager]複製代碼
相關示例完整代碼: springboot-action微信
(完)app
更多精彩文章,盡在「服務端思惟」微信公衆號!