Map<String, Object> map = new HashMap();
        map.put("123","商品1");
        map.put("124","商品2");
        map.put("125","商品3");
        redisTemplate.delete("1");
        redisTemplate.opsForHash().putAll("1",map);
        redisTemplate.expire("1",10,TimeUnit.MINUTES);


        Map<Object, Object> o = redisTemplate.opsForHash().entries("1");

        for (Map.Entry<Object, Object> entry : o.entrySet()) {
            String mapKey = entry.getKey().toString();
            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","修改");
        map1.put("136","新增");
        redisTemplate.opsForHash().putAll("1",map1);
        redisTemplate.opsForHash().put("1","124","修改2");


        Map<Object, Object> k = redisTemplate.opsForHash().entries("1");

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

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

        //获取单个
        Object value = redisTemplate.opsForHash().get("1", "136");
        System.out.println(value);

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐