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 ...
随机推荐
- 直击根源:微信小程序中web-view再次刷新后页面需要退两次
背景 在上一章(直击根源:vue项目微信小程序页面跳转web-view不刷新)解决了vue在小程序回退不刷新的问题之后,会引出了一个刷新的页面需要点击返回两次才能返回上一个页面 问题描述 在A页面从B ...
- 二.安全NA之ASA基础
一.ASA常用命令 show run interface #查看接口配置 show ip address #查看IP地址 show conn #查看防火墙状态信息,U代表up:I,代表进流量:O,代表 ...
- spring-boot-plus详细配置(五)
spring-boot-plus详细配置 公共配置 application.yml
- java 判断 string 转 integer 判断
NumberUtils.isDigits("1") NumberUtils.isDigits("/") 根据返回 true false 再确定是否转换即可 需要 ...
- Django之ORM-model模型属性
Django1.8.2中文文档:Django1.8.2中文文档 或者 https://yiyibooks.cn/xx/django_182/index.html 项目准备 注释:关于项目准备,其实和后 ...
- 通过类来实现多session 运行
#xilerihua import tensorflow as tf import numpy as np import os from PIL import Image import matplot ...
- time_wait状态如何处理和建议
TL;DR: do not enable net.ipv4.tcp_tw_recycle. UPDATED (2017.09): net.ipv4.tcp_tw_recycle has been re ...
- C# winform语音提示
1.SpeechSynthesizer文字转音频 项目添加引用:System.Speech using(SpeechSynthesizer speech = new SpeechSynthesizer ...
- Mac迅雷瘦身精简教程
迅雷是个大家很熟悉的工具了,尽管吐槽的人不少,但相信大家也都是口嫌体直,边骂边用. 其实 macOS 版迅雷在界面上,相比于 Windows 的客户端来说,已经很克制了,但有些功能仍然对用户造成了干扰 ...
- P2154 [SDOI2009]虔诚的墓主人 树状数组
https://www.luogu.org/problemnew/show/P2154 题意 在一个坐标系中,有w(1e5)个点,这个图中空点的权值是正上,正下,正左,正右各取k个的排列组合情况.计算 ...