redis实现缓存集合不需要查询数据库了

1.利用 fastjson吧集合转换为字符串 存储  然后在反向解析就可以了

redis实现缓存集合不需要查询数据库了_第1张图片

 

@GetMapping("findDate")
public Result findDate() throws IOException {
    QueryWrapper borrowerQueryWrapper = new QueryWrapper<>();
    borrowerQueryWrapper.select("name","id");
    //用MP查询指定的字段
    List objects = dictMapper.selectObjs(borrowerQueryWrapper);
    //查询全部
    List list = dictMapper.selectList(null);
    String s = JSONObject.toJSONString(list);
    redisTemplate.opsForValue().set("key1",s);
    String key1 = redisTemplate.opsForValue().get("key1");
    List dicts = JSONObject.parseArray(key1, Dict.class);
    System.out.println(dicts);


    LambdaQueryWrapper gbrm06LambdaQueryWrapper = Wrappers.lambdaQuery();

    gbrm06LambdaQueryWrapper.eq(Dict::getId, null);
    boolean remove = dictService.remove(gbrm06LambdaQueryWrapper);
    boolean b = dictService.removeById(null);
    dictService.list(null);


    //第一种更新方法 利用填充字段和 QueryWrapper来实现
    QueryWrapper objectQueryWrapper = new QueryWrapper<>();
    objectQueryWrapper.in("id","12","13","32").eq("name","大大");
    Dict dict = new Dict();
    dict.setName("测试啊爱还好");
    dictMapper.update(dict,objectQueryWrapper);
    //第二种更新方法,直接用UpdateWrapper来搞
    UpdateWrapper updateWrapper = new UpdateWrapper<>();
    updateWrapper.set("name","gagaga");
    dictMapper.update(null,updateWrapper);


    // List> list = dictService.findDate();
    return Result.ok(objects);
} 
  

redis实现缓存集合不需要查询数据库了_第2张图片

 

你可能感兴趣的:(缓存,redis,数据库)