示例:
@Autowired StringRedisTemplate redisTemplate; @Override public void dealRedis(Dealer dealer) { dealer = dao.findByUid(dealer.getUid()); String tid = dealer.getTenementId(); HashOperations<String, Object, Object> ofh = redisTemplate.opsForHash(); Field[] declaredFields = dealer.getClass().getDeclaredFields(); for (Field declaredField : declaredFields) { String name = declaredField.getName(); if (name.equals("id") || name.equals("tid")){ continue; }else { ofh.increment(tid,name,111); } } Map<Object, Object> entries = ofh.entries(tid); System.out.println("获取Map>>>>>>>>>>>>>>>>>>>>>>>>>>"+entries.toString()); Set<Object> keys = ofh.keys(tid); System.out.println("获取KEY的SET>>>>>>>>>>>>>>>>>>>>>"+keys.toString()); List<Object> values = ofh.values(tid); System.out.println("获取VALUES的LIST>>>>>>>>>>>>>>>>>>>>>"+values.toString()); ofh.delete(tid,keys.toArray()); System.out.println("删除成功>>>>>>>>>>>>>>>>>>>>>>>>>>"); Map<Object, Object> entries2 = ofh.entries(tid); System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>"+entries2.toString()); for (Object key : keys) { ofh.increment(tid,key,111); } Map<Object, Object> entries3 = ofh.entries(tid); System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>"+entries3.toString()); for (Object key : keys) { ofh.increment(tid,key,-11); } Map<Object, Object> entries4 = ofh.entries(tid); System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>"+entries4.toString()); ofh.delete(tid,keys.toArray()); System.out.println("删除成功>>>>>>>>>>>>>>>>>>>>>>>>>>"); for (Object key : keys) { ofh.increment(tid,key,-11); } Map<Object, Object> entries5 = ofh.entries(tid); System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>"+entries5.toString()); }
结果:
原文地址:https://www.cnblogs.com/sxdcgaq8080/p/9562633.html
时间: 2024-10-08 19:30:29