Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7784005
  • 博文数量: 593
  • 博客积分: 13065
  • 博客等级: 上将
  • 技术积分: 10313
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-26 16:44
个人简介

推荐: blog.csdn.net/aquester https://github.com/eyjian https://www.cnblogs.com/aquester http://blog.chinaunix.net/uid/20682147.html

文章分类

全部博文(593)

分类: Java

2016-04-15 15:26:27

对于下段代码:

  1. public List<String> hmget(String key, List<String> fields) throws org.apache.thrift.TException
  2. {
  3.     JedisCluster jedis_cluster = RedisClusterProxy.get_jedis_cluster();
  4.     String[] field_array = new String[fields.size()];
  5.     fields.toArray(field_array);
  6.     return jedis_cluster.hmget(key, field_array);
  7. }

运行时遇到如下异常,原因是由于hmget返回的List含有null成员,导致thrift编码时异常:
20160415 14:55:39 ERROR org.apache.thrift.server.AbstractNonblockingServer$FrameBuffer.invoke(AbstractNonblockingServer.java:484) [Thread-0] Unexpected throwable while invoking!
java.lang.NullPointerException
        at org.apache.thrift.protocol.TBinaryProtocol.writeString(TBinaryProtocol.java:185)
        at com.test.redis_cluster_proxy.RedisClusterProxyService$hmget_result$hmget_resultStandardScheme.write(RedisClusterProxyService.java:19434)
        at com.test.redis_cluster_proxy.RedisClusterProxyService$hmget_result$hmget_resultStandardScheme.write(RedisClusterProxyService.java:1)
        at com.test.redis_cluster_proxy.RedisClusterProxyService$hmget_result.write(RedisClusterProxyService.java:19337)
        at org.apache.thrift.ProcessFunction.process(ProcessFunction.java:53)
        at org.apache.thrift.TBaseProcessor.process(TBaseProcessor.java:39)
        at org.apache.thrift.server.AbstractNonblockingServer$FrameBuffer.invoke(AbstractNonblockingServer.java:478)
        at org.apache.thrift.server.TNonblockingServer.requestInvoke(TNonblockingServer.java:115)
        at org.apache.thrift.server.AbstractNonblockingServer$AbstractSelectThread.handleRead(AbstractNonblockingServer.java:209)
        at org.apache.thrift.server.TNonblockingServer$SelectAcceptThread.select(TNonblockingServer.java:198)
        at org.apache.thrift.server.TNonblockingServer$SelectAcceptThread.run(TNonblockingServer.java:154)
        
当redis中没有相应的field时,hmget返回的List会包含null成员。解决此问题有两个办法:
1)保证查询的field一定存在
2)对hmget返回值做处理,null成员替换成空字符串""
     
阅读(7140) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~