redis序列化和反序列化的操作-(以前咋操作我都忘记了)

//拿到数据,redis如果有则将现在有的传进去,如果没有则获取接口
ExWritPropertyVo ExWritPropertyVo = new ExWritPropertyVo();
ExWritPropertyVo.setCaichanmingcheng("我是打电话的");
ExWritPropertyVo.setCaichanmingchengType(21);
byte[] serialize = SerializationUtils.serialize(ExWritPropertyVo);//lang3包下的
redisTemplate.opsForValue().set("u",serialize);
byte[] bs2 = (byte[]) redisTemplate.opsForValue().get("u");//redisTemplate
ExWritPropertyVo deserialize = SerializationUtils.deserialize(bs2);
System.out.println(deserialize);

 

 

小案例:

    @GetMapping("/test01")
    public R test01(){
        byte[] bs2 = (byte[])redisTemplate.opsForValue().get("zhangsan");
        HashMap<String, String> ccxmapAll = new HashMap<String, String>(16);

        if(bs2!=null){
          ccxmapAll = SerializationUtils.deserialize(bs2);
        }
        if(ccxmapAll.size()<1){
            ccxmapAll.put("zhansgan","dasdsad");
            byte[] serialize = SerializationUtils.serialize(ccxmapAll);//lang3包下的

            redisTemplate.opsForValue().set("zhangsan",serialize);
       }
        return R.ok(ccxmapAll);
    }

  

posted @ 2021-04-06 11:53  三号小玩家  阅读(400)  评论(0编辑  收藏  举报
Title
三号小玩家的 Mail: 17612457115@163.com, 联系QQ: 1359720840 微信: QQ1359720840