springboot---redis缓存的使用
1、下载redis安装包,解压到电脑
2、启动redis
3、springboot application.properties中配置redis缓存
spring.redis.host=127.0.0.1 //redis的地址
spring.redis.port=6379 //端口
//密码,默认为空
spring.redis.password=
# Redis服务器连接密码(默认为空)
spring.redis.password= # 连接池最大连接数(使用负值表示没有限制)
spring.redis.pool.max-active=8 # 连接池最大阻塞等待时间(使用负值表示没有限制)
spring.redis.pool.max-wait=-1 # 连接池中的最大空闲连接
spring.redis.pool.max-idle=8 # 连接池中的最小空闲连接
spring.redis.pool.min-idle=0 # 连接超时时间(毫秒)
spring.redis.timeout=0
使用:
1、
RedisSerializer redisSerializer = new StringRedisSerializer();
@Autowired
private RedisTemplate<Object, Object> redisTemplate; 2、方法体中使用:
@Override
public Page<Product> getProductListByPage(int page, String productType, int count, Sort sort) {
redisTemplate.setKeySerializer(redisSerializer); //序列化
Page<Product> product= (Page<Product>) redisTemplate.opsForValue().get("getProduct"); //从缓存中获取数据
if (product==null){
synchronized (new Object()){
if (product==null){
Specification<Product> specification=pageableTool.specifucation(productType);
Pageable pageable = PageRequest.of(page, count, sort);
product= productRepository.findAll(specification, pageable);
redisTemplate.opsForValue().set("getProduct",product); //将数据写入redis缓存中
return product;
}
}
}
return product;
}
3、实体类必须实现 Serializable (redis包自带的)

springboot---redis缓存的使用的更多相关文章
- springboot redis 缓存对象
只要加入spring-boot-starter-data-redis , springboot 会自动识别并使用redis作为缓存容器,使用方式如下 gradle加入依赖 compile(" ...
- SpringBoot Redis缓存 @Cacheable、@CacheEvict、@CachePut
文章来源 https://blog.csdn.net/u010588262/article/details/81003493 1. pom.xml <dependency> <gro ...
- springboot Redis 缓存
1,先整合 redis 和 mybatis 步骤一: springboot 整合 redis 步骤二: springboot 整合 mybatis 2,启动类添加 @EnableCaching 注解, ...
- springboot + redis缓存使用
[参照资料] 1.spring boot 官网文档 2.https://www.cnblogs.com/gdpuzxs/p/7222309.html [项目结构] [pom.xml配置] <?x ...
- 从.Net到Java学习第七篇——SpringBoot Redis 缓存穿透
从.Net到Java学习系列目录 场景描述:我们在项目中使用缓存通常都是先检查缓存中是否存在,如果存在直接返回缓存内容,如果不存在就直接查询数据库然后再缓存查询结果返回.这个时候如果我们查询的某一个数 ...
- 微服务-Springboot+Redis缓存管理接口代码实现
废话少说,上代码,结合代码讲解: 一.创建maven工程:导入依赖: <packaging>war</packaging><!--修改jdk的版本--><pr ...
- springboot redis 缓存跨域丢失问题
对于前后端分离的项目,在开发阶段经常会遇到跨域的问题. 1.首先,对于后台的处理方式,第一种是用 @CrossOrigin 注解,@crossorigin是后端SpringMVC框架(需4.2版本以上 ...
- spring-boot的spring-cache中的扩展redis缓存的ttl和key名
原文地址:spring-boot的spring-cache中的扩展redis缓存的ttl和key名 前提 spring-cache大家都用过,其中使用redis-cache大家也用过,至于如何使用怎么 ...
- SpringBoot学习笔记(6) SpringBoot数据缓存Cache [Guava和Redis实现]
https://blog.csdn.net/a67474506/article/details/52608855 Spring定义了org.springframework.cache.CacheMan ...
- java框架之SpringBoot(11)-缓存抽象及整合Redis
Spring缓存抽象 介绍 Spring 从 3.1 版本开始定义了 org.springframework.cache.Cache 和 org.springframework.cache.Cache ...
随机推荐
- C++7行代码实现求最大公约数
最近在做奥赛题时碰到求最大公约数的问题,给出解决方案: int gcd(int a,int b){ int tmp = a%b; ){ return b; } else{ return gcd(b,t ...
- 右键新建 .md
右键新建 .md 文件 声明:虽然我成功了,并且右键出来了两个,但是在添加 .html 的过程中又失败了,找不到解决办法. win + r --> regedit --> enter 点击 ...
- 一个简单的Python调度器Schedule
关于我 一个有思想的程序猿,终身学习实践者,目前在一个创业团队任team lead,技术栈涉及Android.Python.Java和Go,这个也是我们团队的主要技术栈. Github:https:/ ...
- linux 如何初始化密码(解决mysql root用户登录不了的问题)
这是我遇到的问题 然后就想这可能是mysql安全模式的问题,解决思路:首先改变mysql的安全模式及密码校验问题,jinrumysql后在更改用户名密码. 1.首先将my.ini中加入在[mysqld ...
- java web基础 js、JSP、servlet之间的传递
@ JS 与 JSP :JSP无法直接获取JS的值,只能通过隐藏表单或者dom节点设置. JSP中设置隐藏表单input,或者设置任意一个隐藏或者不隐藏的节点比如div, 而JS就通过document ...
- 变量声明关键字var ,let,const
今天带大家了解的是比较有趣的几个变量声明关键字var,let,const. 我们在最初接触JS的时候,变量是我们重要的一个组成部分,在使用时规定必须要先进行声明,否则网页将会报错: console.l ...
- Leetcode之深度优先搜索(DFS)专题-515. 在每个树行中找最大值(Find Largest Value in Each Tree Row)
Leetcode之深度优先搜索(DFS)专题-515. 在每个树行中找最大值(Find Largest Value in Each Tree Row) 深度优先搜索的解题详细介绍,点击 您需要在二叉树 ...
- (五十二)c#Winform自定义控件-LED数字
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. GitHub:https://github.com/kwwwvagaa/NetWinformControl 码云:ht ...
- vue实现手机号码的校验(防抖函数的应用场景)
上一篇博文我们讲到了节流函数的应用场景,我们知道了节流函数可以用在模糊查询.scroller.onresize等场景:今天这篇我们来讲防抖函数的应用场景:: 通过上一篇博文的学习,我们知道了防抖函数的 ...
- 在windows7系统下如何查看及升级powershell到3.0版本
最近在学习.net core web api 开发,用到了Mysql.Data.EntityFrameworkCore框架,在根据数据库表生成对应实体类时提示必须先升级本机powershell到3.0 ...