本文,讲解 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
更多精彩文章,尽在「服务端思惟」微信公众号!