hmset命令报错 value sent to redis cannot be null

来源:互联网 发布:java log4j2.xml 编辑:程序博客网 时间:2024/06/05 19:55

redis存入hash结构时, key, hkey, hvalue 均不能为null

public void hmset(final String key, final Map<String, String> hash) {    final Map<byte[], byte[]> bhash = new HashMap<byte[], byte[]>(hash.size());    for (final Entry<String, String> entry : hash.entrySet()) {      bhash.put(SafeEncoder.encode(entry.getKey()), SafeEncoder.encode(entry.getValue()));    }    hmset(SafeEncoder.encode(key), bhash);  }

public static byte[] encode(final String str) {    try {      if (str == null) {        throw new JedisDataException("value sent to redis cannot be null");      }      return str.getBytes(Protocol.CHARSET);    } catch (UnsupportedEncodingException e) {      throw new JedisException(e);    }  }


阅读全文
0 0