@Resource(name
= "redisTemplate")
private
HashOperations<String,
String,
Object>
hashOps;
@Test
public void
test4()
throws
Exception{
String
key =
"test_User_shopping:"
+ 2;
//id为2的用户的购物车;
hashOps.put(key,"3",5+"");
hashOps.put(key,"4",2+"");
hashOps.put(key,"6",1+"");
Map<String,
Object>
map2
= hashOps.entries(key);//返回map集合
//用户购物车的列表为,3号商品5个,4号2个,6号1个;
hashOps.increment(key,"6",2);//用户再次添加商品6号2个,
Map<String,Object>
objectMap=new
HashMap<>();
objectMap.put("7",3+"");
objectMap.put("9",3+"");
hashOps.putAll(key,objectMap);//批量添加
Map<String,
Object>
map3
= hashOps.entries(key);//返回map集合
hashOps.delete(key,"6");//移除商品6号;
Map<String,
Object>
map4
= hashOps.entries(key);//返回map集合
Boolean
age1
= hashOps.hasKey(key,
"9");//是否存在hash字段
Object
age2
= hashOps.get(key,
"9");//获取hash字段的值;
Set<String>
keys
= hashOps.keys(key);//返回map的key集合Set
Long
size
= hashOps.size(key);//返回列表的大小,
List<Object>
values
= hashOps.values(key);//返回值的集合;
List<String>
hashkeys
= new
ArrayList<>();
hashkeys.add("7");
hashkeys.add("9");
List<Object>
objects
= hashOps.multiGet(key,
hashkeys);//批量获取,
}