本文部分步骤继承于springboot使用cache缓存,如果有不清楚的,请移驾springboot使用cache缓存
spring-boot-starter-cache
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
当你导入这一个依赖时,SpringBoot
的CacheManager
就会使用RedisCache
。
如果你的Redis
使用默认配置,这时候已经可以启动程序了。
spring:
cache:
type: redis
redis:
# Redis数据库索引(默认为0)
database: 8
# Redis服务器地址
host: 10.168.1.209
# Redis服务器连接端口
port: 6379
# Redis服务器连接密码(默认为空)
password: ''
pool:
# 连接池最大连接数(使用负值表示没有限制)
max-active: 1000
# 连接池最大阻塞等待时间(使用负值表示没有限制)
max-wait: -1
# 连接池中的最大空闲连接
max-idle: 10
# 连接池中的最小空闲连接
min-idle: 2
# 连接超时时间(毫秒)
timeout: 0
整合完毕!
别忘了在启动类开启缓存!
源码地址:https://gitee.com/LiZhendd/demo