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开始提供了强大的基于注解的缓 ...
随机推荐
- vue+element项目中过滤输入框特殊字符小结
可以在main.js中写入方法 Vue.prototype.validSe = function (value, number = 255) { value = value.replace(/[`-* ...
- jquery判断元素是否包含某class
// <div id="id" class="add on"></div> var flag = $("#id"). ...
- solr后台【web页面】增删改查
就是在下面这个页面操作 增加 {"id":"2", "name": "添加"} 查询 id:2 修改 {"id ...
- [CF1070A]Find a Number_bfs
Find a Number 题目链接:http://codeforces.com/problemset/problem/1070/A 数据范围:略. 题解: 因为$d$和$s$比较小可以搜. 这就很$ ...
- airflow删除dag不在页面显示
当我们需要把dag删除的时候,遇到了删除了相应的dag文件,但页面还是显示 这个时候需要重启airflow 的webserver ps -ef|egrep rm -rf /home/airflow ...
- GCC 高版本7.4 编译链接 boost 报错 boost::thread::XXX’未定义的引用 解决方法
背景:开发中的项目之前一直用GCC4.8,boost库1.48版本的开发环境.现在因业务需求,需要更换GCC7.4,boost库1.70. 问题:可以正常编译BOOST的链接库文件,但是链接时候报错. ...
- Python笔记day20-面向对象
目录 面向对象 1 装饰器 1.1 装饰器是什么? 1.2 装饰器 2 面向对象 (Object Oriented) 简称OO 2.1 面向对象相关术语 2.2 类和对象 2.3 类和对象的实现和书写 ...
- Python习题006
作业一:打印10*10 星星 ★☆ 要求一:普通打印★ l = 0 while l <10: h = 0 while h < 9: print("★", end=&q ...
- Python使用datetime来判断近七天
目录 strptime 使用strptime来格式化字符串 datetime.datetime.strptime("2019-10-02", "%Y-%m-%d" ...
- docker部署Eurake服务,服务节点无法注册服务
前言 昨天在部署一个docker项目时遇到了一个问题,故记录下来. 环境说明 Centos7 Docker version 18.06.3-ce, build d7080c1 问题说明 该项目分别启动 ...
问题:key乱码 可参考另一篇博客解决办法 https://www.cnblogs.com/shuaifing/p/11213253.html