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包自带的)


最新文章

  1. ASP.NET Core的配置(5):配置的同步[设计篇]
  2. resizable.js
  3. 改造rm命令为mv
  4. 续Gulp使用入门-综合运用&gt;使用Gulp构建一个项目
  5. textView中判断文本长度,自定义表情长度为1,emoj表情长度为1,输入限制
  6. 【JAVA、C++】LeetCode 010 Regular Expression Matching
  7. C++话题
  8. UVA11552------FEWEST FLOPS------区间型的DP
  9. DWR3.0 服务器推送及解惑
  10. c++继承学习
  11. 关于word粘贴图片无法显示的原因
  12. 工作中遇到的问题——mysql关于年龄,性别的统计
  13. C语言权威指南和书单 - 适用于所有级别
  14. CentOS5.5 - lnmp环境安装与使用
  15. Qt5全局热键第三方库qxtglobalshortcut5使用
  16. Fabric实例
  17. [转]Scrapy简单入门及实例讲解
  18. 神文章2:文本矩阵简述 V1.0 -vivo神人
  19. Linux进程间通信--使用信号量【转】
  20. TeamWork#3,Week5,Bing Input Method vs Sogou Input Method

热门文章

  1. 解决 Nginx 代理Apex慢的问题
  2. StudyAndroid.2 Activity生命周期
  3. 线程的start方法解析
  4. json模块和pickle模块
  5. 线上ZK问题排查
  6. @RequestBody 注意的问题
  7. FaceNet人脸识别研究
  8. Django2.0使用
  9. 解决Ubuntu安装mysql中的一些问题
  10. Python从入门到精通之环境搭建