springboot使用redis缓存

在application中配置:

spring.redis.host=127.0.0.1

spring.redis.port=6379

#连接池最大连接数

spring.redis.jedis.pool.max-active=8

#最小空闲连接

spring.redis.jedis.pool.min-idle=0

#最大阻塞等待时间,负值表示没有限制

spring.redis.jedis.pool.max-wait=-1

#最大空闲连接

spring.redis.jedis.pool.max-idle=8

#连接超时时间(毫秒)

spring.redis.timeout=20

开启缓存:

@SpringBootApplication

@EnableCaching//开启缓存

public class ErpApplication {

public static void main(String[] args) {

SpringApplication.run(ErpApplication.class, args);

}

}

使用以下三大注解,放在方法上,或者是类上:

@Cacheable(value="") 注释指示可以缓存调用方法(或类中的所有方法)的结果。value值是缓存的名称

@CacheEvict(value="") 注释指示方法(或类上的所有方法)触发高速缓存逐出操作。value值是缓存的名称

@CachePut(value="") 注释指示方法(或类上的所有方法)触发缓存放置操作。value值是缓存的名称

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容