redis中通过redisTemplate存放后再修改map值(遍历Map),同时得到map里面value对象的属性值

redis中通过redisTemplate存放后再修改map值,遍历Map,同时得到map里面value对象的属性值

代码(分为三个测试):

@Autowired
private RedisTemplate redisTemplate;
@Test
    public void test03(){
        Map<String, Object> map = new HashMap();
        map.put("123","商品1");
        map.put("124","商品2");
        map.put("125","商品3");
        Store store = new Store();
        store.setBusinessLicense("测试商品1");
        map.put("126",store);
        redisTemplate.opsForValue().set("1",map);

        Map<String, Object> o = (Map)redisTemplate.opsForValue().get("1");

        for (Map.Entry<String, Object> entry : o.entrySet()) {
            String mapKey = entry.getKey();
            Object mapValue = entry.getValue();
            System.out.println("key= "+mapKey+" ,value= "+mapValue);
        }

        System.out.println("~~~~~~~~~~~~~~~~~~~~~~测试一结束(遍历redis存放的map)~~~~~~~~~~~~~~~~~~~~~~~~");

        Map<String, Object> map1 = new HashMap();
        map1.put("123","商品1");
        map1.put("124","商品2");
        map1.put("125","商品4");
        map1.put("126","商品5");
        Store store1 = new Store();
        store1.setBusinessLicense("测试商品2");
        map1.put("136",store1);
        redisTemplate.opsForValue().set("1",map1,10, TimeUnit.MINUTES);

        Map<String, Object> k = (Map)redisTemplate.opsForValue().get("1");

        for (Map.Entry<String, Object> entry : k.entrySet()) {
            String mapKey = entry.getKey();
            Object mapValue = entry.getValue();
            System.out.println("key= "+mapKey+" ,value= "+mapValue);
        }

        System.out.println("~~~~~~~~~~~~~~~~~~~~~~测试二结束(修改redis里面的map)~~~~~~~~~~~~~~~~~~~~~~~~");

        Map<String, Object> m = (Map)redisTemplate.opsForValue().get("1");
        JSONObject jsonObject =  (JSONObject)m.get("136");
        Store s = JSONObject.toJavaObject(jsonObject, Store.class);
        System.out.println(s.getBusinessLicense());

        System.out.println("~~~~~~~~~~~~~~~~~~~~~~测试三结束(取map里面存放的map对象的一个属性值)~~~~~~~~~~~~~~~~~~~~~~~~");
    }
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值