pom:
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-redis -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<version>2.6.1</version>
</dependency>
application.yml:
spring:
cache:
type: redis
ehcache:
config: classpath:/ehcache.xml
cache-names: sys
redis:
host: 127.0.0.1
port: 6379
password:
database: 8
jedis:
pool:
# 最大空闲连接数
max-idle: 30
# 最小空闲连接数
min-idle: 1
# 最大活跃连接数,负数为不限制
max-active: 20
# 等待可用连接的最大时间,负数为不限制
max-wait: 2
service使用:
@Cacheable(key = "#key",value = "sys")
public Page<TestOne> listCache(String key){
Page<TestOne> page = new Page<>();
page = baseMapper.selectPage(page,null);
return page;
}