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 ...
随机推荐
- Json对象转Ts类
一 目标 推荐一款在线将Json对象转换为Ts类的工具:https://apihelper.jccore.cn/jsontool 可以帮助前端开发人员提高开发效率. 二 背景 Json是一种轻量级的数 ...
- Go语言框架:Beego vs Gin 的区别
前言: 一切语言.技术或者框架,本质都是工具,工具的价值在于为使用者提供竞争优势. 一.Beego和Gin全方位比较 MVC Beego支持完整的MVC, Gin不支持完整的MVC(需要开发者自己实现 ...
- 教你如何认识人脸识别开发套件中的双目摄像、3D结构光摄像头、单目摄像头的区别及详细讲解
深圳市宁远电子提供的人脸识别模组可支持双目摄像头和3D结构光摄像头,在客户咨询中经常有被问到双目的为什么会比单目的成本高,区别在哪里,他们的适用于哪些场景呢?在此,深圳市宁远电子技术工程师就为大家详细 ...
- Cocos2d-x 学习笔记(21) ScrollView (CCScrollView)
1. 简介 CCScrollView.cpp文件内的滚动视图ScrollView直接继承了Layer+ActionTweenDelegate. 滚动视图能在屏幕区域内,用户通过触摸拖动屏幕,实现大于屏 ...
- Kafka监控工具汇总
对于大数据集群来说,监控功能是非常必要的,通过日志判断故障低效,我们需要完整的指标来帮我们管理Kafka集群.本文讨论Kafka的监控以及一些常用的第三方监控工具. 一.Kafka Monitorin ...
- random库的使用
一.random库介绍 random库是使用随机数的Python标准库 伪随机数:采用梅森旋转算法生成的(伪)随机序列中元素 random库主要用于生成随机数 使用random库:import ran ...
- SynchronousQueue队列程序的执行结果分析
public static void main(String[] args) throws Exception { /** * SynchronousQueue队列程序的执行结果分析 * Blocki ...
- deepin 15.11 安装 pyenv
GitHub:官方环境:https://github.com/pyenv/pyenv/wiki/Common-build-problems GitHub:官方文档:https://github.com ...
- Vue 关于多个父子组件嵌套传值
prop 是单向绑定的:当父组件的属性变化时,将传导给子组件,但是不会反过来.这是为了防止子组件无意修改了父组件的状态——这会让应用的数据流难以理解. props: { selectMember: { ...
- PHP面相对象编程-重载、覆盖(重写) 多态、接口
http://www.ctolib.com/topics-21262.html http://cnn237111.blog.51cto.com/2359144/1284085 http://blog. ...