springboot中使用cache和redis
知识点:springboot中使用cache和redis
(1)springboot中,整合了cache,我们只需要,在入口类上加 @EnableCaching 即可开启缓存
例如:在service层使用@Cacheable和CacheEvict
//添加缓存
@Cacheable(cacheNames = "TestCACHE",key = "#root.methodName +'_'+ #id")
public Map<String, Object> testSetCache(Integer id){
Map<String, Object> user = userMapper.findUserById(id);
return user;
} //清除缓存
@CacheEvict(cacheNames = "TestCACHE", allEntries = true)
public Boolean testEvictCache(){
return true;
} (2)引入redis依赖,将Cache中的数据放到redis数据库中,然后从redis中取数据 a.引入依赖
<!--加入redis依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
b.application.yml中设置redis连接等配置
redis:
host: 192.10.21.237
port: 6379
database: 5
password:
timeout: 1800000
jedis:
pool:
max-idle: 10
min-idle: 0
max-active: 10
max-wait: 1000 存入redis的数据如下问题:key乱码 可参考另一篇博客解决办法 https://www.cnblogs.com/shuaifing/p/11213253.html
之后会总结1.cache其他用法 2.springboot中的原理 参考:https://blog.csdn.net/weixin_36279318/article/details/82820880
springboot中使用cache和redis的更多相关文章
- SpringBoot中Shiro缓存使用Redis、Ehcache
在SpringBoot中Shiro缓存使用Redis.Ehcache实现的两种方式实例 SpringBoot 中配置redis作为session 缓存器. 让shiro引用 本文是建立在你是使用这sh ...
- springboot整合spring @Cache和Redis
转载请注明出处:https://www.cnblogs.com/wenjunwei/p/10779450.html spring基于注解的缓存 对于缓存声明,spring的缓存提供了一组java注解: ...
- springboot中各个版本的redis配置问题
今天在springboot中使用数据库,springboot版本为2.0.2.RELEASE,通过pom引入jar包,配置文件application.properties中的redis配置文件报错,提 ...
- SpringBoot 结合 Spring Cache 操作 Redis 实现数据缓存
系统环境: Redis 版本:5.0.7 SpringBoot 版本:2.2.2.RELEASE 参考地址: Redus 官方网址:https://redis.io/ 博文示例项目 Github 地址 ...
- 在SpringBoot中存放session到Redis
前言 今天你们将再一次领略到SpringBoot的开发到底有多快,以及SpringBoot的思想(默认配置) 我们将使用redis存放用户的session,用户session存放策略有很多,有存放到内 ...
- springboot 中 集成druid ,redis
1,导入druid jar包 <!--引入drud--> <dependency> <groupId>com.alibaba</groupId> < ...
- SpringBoot中整合Redis、Ehcache使用配置切换 并且整合到Shiro中
在SpringBoot中Shiro缓存使用Redis.Ehcache实现的两种方式实例 SpringBoot 中配置redis作为session 缓存器. 让shiro引用 本文是建立在你是使用这sh ...
- springboot中,使用redisTemplate操作redis
知识点: springboot中整合redis springboot中redisTemplate的使用 redis存数据时,key出现乱码问题 一:springboot中整合redis (1)pom. ...
- SpringBoot(七) SpringBoot中的缓存机制
随着时间的积累,应用的使用用户不断增加,数据规模也越来越大,往往数据库查询操作会成为影响用户使用体验的瓶颈,此时使用缓存往往是解决这一问题非常好的手段之一.Spring 3开始提供了强大的基于注解的缓 ...
随机推荐
- Python 日志文件处理
今天想把 Python 项目中的日志 保存到文件中. 找到了方法.非常简单 https://www.cnblogs.com/nancyzhu/p/8551506.html 1. logging.bas ...
- JAVA_split 字符串按照 . 分割
split 按照 . 分割字符串时 需要进行转义 代码: String[] str = obj_str.split("\\.") split 按照 \ 分割字符串时 需要多次转义 ...
- Maven打包成可执行JAR(带依赖包)
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> ...
- 正则与re模块
一.正则表达式 在线测试工具 http://tool.chinaz.com/regex/ 1.字符组 在同一个位置可能出现的各种字符组成一个字符组,在正则表达中用[ ]表示 一个正则就是一条匹 ...
- Django打印出在数据库中执行的语句
有时我们需要看models操作时对应的SQL语句, 可以用如下方法查看--- 在django project中的settings文件尾部添加如下代码 LOGGING = { 'version': 1, ...
- SAS学习笔记23 线性回归、多元回归
线性回归 由样本资料计算的回归系数b和其他统计量一样,存在抽样误差,因此,需要对线性回归方程进行假设检验 1.方差分析 2.t检验 相关系数的假设检验 相关系数(correlation coeffic ...
- ASP.NET Core 过滤器
继承Attribute,IActionFilter实现自己的过滤器类,并且在Startup,mvc服务中注入. 全局都会过滤,在任意一个controller,action执行前和执行后都会过滤一次 通 ...
- Largest Submatrix 3 CodeForces - 407D (dp,好题)
大意: 给定矩阵, 求选出一个最大矩形, 满足矩形内每个元素互不相同. 考虑枚举上下左三个边界, 求出最大右边界的位置. 注意到固定上边界, 下边界递推时, 每个左边界对应最大右边界是单调不增的. 所 ...
- Java InsertionSort
Java InsertionSort /** * <html> * <body> * <P> Copyright 1994-2018 JasonInternatio ...
- 在Angular中使用$ compile
转载自:http://odetocode.com/blogs/scott/archive/2014/05/07/using-compile-in-angular.aspx 在AngularJS中创建一 ...
问题:key乱码 可参考另一篇博客解决办法 https://www.cnblogs.com/shuaifing/p/11213253.html