资料来源:https://blog.csdn.net/XinhuaShuDiao/article/details/84911561

    1. // 首先要定义一个BoundHashOperations
    2. BoundHashOperations<String, String, Object> boundHashOperations = redisTemplate.boundHashOps("li");
    3. // 1、put(HK key, HV value):新增元素到指定键中
    4. boundHashOperations.put("ww","i");
    5. boundHashOperations.put("w1","i1");
    6. boundHashOperations.put("w2","i2");
    7. // 2、getKey():获取指定键中的值
    8. System.out.println("获取设置的绑定key值:" + boundHashOperations.getKey());
    9. // 3、values():获取map中的值jdk要求1.8及以上
    10. boundHashOperations.values().forEach(v -> System.out.println("获取map中的value值" + v));
    11. // 4、entries():获取map中的键值对
    12. boundHashOperations.entries().forEach((m,n) -> System.out.println("获取map键值对:" + m + "-" + n));
    13. // 5、get(Object member):获取map键中的值
    14. System.out.println("获取map建的值:" + boundHashOperations.get("w1"));
    15. // 6、keys():获取map的键
    16. boundHashOperations.keys().forEach(v -> System.out.println("获取map的键:" + v));
    17. // 7、multiGet(Collection<HK> keys):根据map键批量获取map值
    18. List list = new ArrayList<>(Arrays.asList("ww","w1"));
    19. boundHashOperations.multiGet(list).forEach(v -> System.out.println("根据map键批量获取map值:" + v));
    20. // 8、putAll(Map<? extends HK,? extends HV> m):批量添加键值对
    21. Map map = new HashMap<>();
    22. map.put("m1","n1");
    23. map.put("m2","n2");
    24. boundHashOperations.putAll(map);
    25. boundHashOperations.entries().forEach((m,n) -> System.out.println("批量添加键值对:" + m + "-" + n));
    26. // 9、increment(HK key, long delta):自增长map键的值
    27. boundHashOperations.increment("c",1);
    28. System.out.println("自增长map键的值:" + boundHashOperations.get("c"));
    29. // 10、putIfAbsent(HK key, HV value):添加不存在的map键
    30. boundHashOperations.putIfAbsent("m2","n2-1");
    31. boundHashOperations.putIfAbsent("m3","n3");
    32. boundHashOperations.entries().forEach((m,n) -> System.out.println("新增不存在的键值对:" + m + "-" + n));
    33. // 11、size():获取特定键对应的map大小
    34. System.out.println("查看绑定建的map大小:" + boundHashOperations.size());
    35. // 12、scan(ScanOptions options):扫描特定键所有值
    36. Cursor<Map.Entry<String, Object>> cursor = boundHashOperations.scan(ScanOptions.NONE);
    37. while (cursor.hasNext()){
    38. Map.Entry<String, Object> entry = cursor.next();
    39. System.out.println("遍历绑定键获取所有值:" + entry.getKey() + "---" + entry.getValue());
    40. }
    41. // 13、delete(Object... keys):批量删除map值
    42. long delSize = boundHashOperations.delete("m3","m2");
    43. System.out.println("删除的键的个数:" + delSize);
    44. boundHashOperations.entries().forEach((m,n) -> System.out.println("删除后剩余map键值对:" + m + "-" + n));