最近使用到的技术与坑20190630-1

本文介绍了在使用Java反射将对象存入Jedis时遇到的'ERR wrong number of arguments for 'hset' command'错误,以及解决方法。同时探讨了CGlib和JDK动态代理在资源关闭场景的应用,并分析了Jedis报错的原因,指出问题源于Redis服务器版本过低。最终,作者提供了一个专门处理Map的工具进行测试。
摘要由CSDN通过智能技术生成

1.java反射   bean2Map

本开打算使用jedis hset(final String key, final Map<String, String> hash)把对象缓存到redis,结果遇到了下面 ERR wrong number of arguments for 'hset' command的错误,导致有点无奈,既然写了,纪念一下

package util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import exception.CustomException;
import lombok.extern.slf4j.Slf4j;
import model.RunTimeStatus;
import org.springframework.beans.BeanUtils;

import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 * @program: netty_study
 * @description:
 * @author: dyingstraw
 * @create: 2019-06-29 15:57
 **/
@Slf4j
public class CommonUtil {

    /**
     * bean2map
     * @param o
     * @return
     */
    public static Map<String, String> beanToMap(Object o) {
        Field[] fields = o.getClass().getDeclaredFields();
        Map<String, String> map = new HashMap<>();
        Arrays.asList(fields).stream().forEach(e -> {
            try {
                e.setAccessible(true);
                map.put(e.getName(), (e.get(o)).toString());
            } catch (IllegalAccessException ex) {
                ex.printStackTrace();
            }
        });
        return map;
    }

    /**
     * map
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值