redis操作map
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.ex...
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);
更多推荐
所有评论(0)