首页 技术 正文
技术 2022年11月18日
0 收藏 402 点赞 4,181 浏览 1421 个字

保存Redis

第一步:启动类中加入注解 @EnableCaching

package com.payease;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;@SpringBootApplication
//@MapperScan(basePackages = "com.payease.dataobject.mapper")
@EnableCaching
public class SellApplication { public static void main(String[] args) {
SpringApplication.run(SellApplication.class, args);
}
}

第二步:在对应的controller中的方法中加入 @Cacheable()

springboot项目:Redis缓存使用

第三步:对该方法的返回值 ResultVO 类中实现Serializable

注:需要安装插件 1.快捷键   command +  ,

         2.点击Plugins 搜索 serializable

springboot项目:Redis缓存使用

     3.安装 插件 重启idea

springboot项目:Redis缓存使用

springboot项目:Redis缓存使用

  4.为插件设置快捷键

     a.左键点击屏幕左上角: IntelliJ IDEA

     b.点击选项菜单:Preferences 打开设置对话框

     c.在左侧的导航框中点击: KeyMap

    springboot项目:Redis缓存使用

    d.在红框内右键选择 springboot项目:Redis缓存使用

    e.设置快捷键 shift + control + i 点击OK springboot项目:Redis缓存使用

    springboot项目:Redis缓存使用

    

package com.payease.VO;import lombok.Data;import java.io.Serializable;/**
* http请求返回最外层对象
* Created by liuxiaoming on 2017/11/11.
*/
@Data
//@JsonInclude(JsonInclude.Include.NON_NULL)
public class ResultVO<T> implements Serializable{ private static final long serialVersionUID = 816318696842351963L;/** 错误码 */
private Integer code; /** 提示信息 */
private String msg; /** 具体内容 */
private T data;
}

第四步:启动项目 在浏览器中输入:127.0.0.1:8080/sell/buyer/product/list

第五步:打开rdm  查看 此时调用controller的方法中的返回值resultVO已经被序列化保存到Redis服务器中

springboot项目:Redis缓存使用

更新Redis(对数据库数据进行更新操作后):

两种方式:

  第一种: @CachePut()更新缓存  需要将返回值序列化

  第二种: @CacheEvict() 清除缓存

springboot项目:Redis缓存使用

注:rdm 手动清除缓存

  1.打开控制台

  springboot项目:Redis缓存使用

  2.输入命令 flushdb

  springboot项目:Redis缓存使用

注:Redis中的 @CachePut()的调用

第一种:

springboot项目:Redis缓存使用

第二种:

springboot项目:Redis缓存使用

扩展:

springboot项目:Redis缓存使用

在浏览器中输入请求:http://127.0.0.1:8080/sell/buyer/product/list?sellerId=1234

总结:

springboot项目:Redis缓存使用

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,105
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,582
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,429
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,200
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,836
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,919