/**
* 操作hash
*/
@Test
public void testHash(){
HashOperations hashOperations = redisTemplate.opsForHash();
/**
*添加一条数据
* 第一个参数:redis的key
* 第二个参数:hash的key
* 第三个参数:hash的value
*/
hashOperations.put("user", "name", "zhangsan");
//获取一条数据
String name = (String) hashOperations.get("user", "name");
//添加多条数据
Map<String,String> map = new HashMap<>();
map.put("age", "20");
map.put("address", "cs");
hashOperations.putAll("user", map);
//获取多条数据
List<String> keys = new ArrayList<>();
keys.add("name");
keys.add("age");
keys.add("address");
List user = hashOperations.multiGet("user", keys);
user.forEach(System.out::println);
//获取hash类型的所有数据
Map<String,String> entries = hashOperations.entries("user");
entries.entrySet().forEach(e ->{
System.out.println(e.getKey()+"-->"+e.getValue());
});
//hash的删除
hashOperations.delete("user", "name","age");
}