【redis】spring boot中 使用redis hash 操作

2021-07-10 09:05

阅读:326

标签:operation   ash   tostring   string   lse   ons   equals   etc   dea   

示例:

@Autowired
    StringRedisTemplate redisTemplate;

    @Override
    public void dealRedis(Dealer dealer) {

        dealer = dao.findByUid(dealer.getUid());
        String tid = dealer.getTenementId();

        HashOperations 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 entries = ofh.entries(tid);
        System.out.println("获取Map>>>>>>>>>>>>>>>>>>>>>>>>>>"+entries.toString());
        Set keys = ofh.keys(tid);
        System.out.println("获取KEY的SET>>>>>>>>>>>>>>>>>>>>>"+keys.toString());
        List values = ofh.values(tid);
        System.out.println("获取VALUES的LIST>>>>>>>>>>>>>>>>>>>>>"+values.toString());

        ofh.delete(tid,keys.toArray());
        System.out.println("删除成功>>>>>>>>>>>>>>>>>>>>>>>>>>");
        Map entries2 = ofh.entries(tid);
        System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>"+entries2.toString());

        for (Object key : keys) {
            ofh.increment(tid,key,111);
        }
        Map entries3 = ofh.entries(tid);
        System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>"+entries3.toString());


        for (Object key : keys) {
            ofh.increment(tid,key,-11);
        }
        Map 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 entries5 = ofh.entries(tid);
        System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>"+entries5.toString());

    }

 

 

结果:

技术分享图片

 

【redis】spring boot中 使用redis hash 操作

标签:operation   ash   tostring   string   lse   ons   equals   etc   dea   

原文地址:https://www.cnblogs.com/sxdcgaq8080/p/9562633.html


评论


亲,登录后才可以留言!