SpringBoot------Redis缓存和数据库对比

1.修改UserInfoController.java

备注:

UserInfoService其余部分代码可参考:

https://www.cnblogs.com/tianhengblogs/p/15322852.html

@RestController
@RequestMapping("/user-info")
public class UserInfoController {

    @Autowired
    private UserInfoService userInfoService;

    //测试
    @GetMapping("/list2")
    public Object getList2() {
     //从数据库获取一条数据 UserInfo userInfo
= userInfoService.findUserInfoByCode("YH006"); return "success"; } @GetMapping("/list3") public Object getList3() {
//从缓存获取一条数据 UserInfo userInfo
= userInfoService.findUserInfoCache("YH006"); return "success"; } }

2.启动Centos7虚拟机,并安装Apache ab测试工具

安装:

yum install -y httpd-tools

备注:

ab -n100 -c10 http://主机地址:测试端口/user/user-info/list2
-n: 进行http请求的总个数
-c:请求的client个数,也就是请求并发数
qps:即每秒并发数,request per second

测试结果:

当http请求总数和请求并发数非常大时,qps就会差的很大了

list2接口(DB)

list3接口(Redis)

 

原文地址:https://www.cnblogs.com/tianhengblogs/p/15323666.html