0

私は netty と redis (jedis クライアント) を使用しており、このコマンドを使用して Apache ベンチマークでテストすると、各リクエストで redisdb 呼び出しのクエリ メソッドが呼び出されます。

ab -c 10 -n 10 ローカルホスト:2080

以下のエラーが発生します。

    Mar 10, 2014 3:29:48 PM io.netty.channel.DefaultChannelPipeline$TailHandler exceptionCaught
WARNING: An exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception.
java.lang.NullPointerException
    at redis.clients.jedis.Protocol.sendCommand(Protocol.java:39)
    at redis.clients.jedis.Protocol.sendCommand(Protocol.java:33)
    at redis.clients.jedis.Connection.sendCommand(Connection.java:80)
    at redis.clients.jedis.BinaryClient.append(BinaryClient.java:200)
    at redis.clients.jedis.Client.append(Client.java:125)
    at redis.clients.jedis.Jedis.append(Jedis.java:616)
    at com.kdgames.server.asyncdatabase.redisdb.query(redisdb.java:14)
    at ServerInboundHandler.channelRead0(ServerInboundHandler.java:41)
    at ServerInboundHandler.channelRead0(ServerInboundHandler.java:1)
    at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:103)
    at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:340)
    at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:326)
    at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86)
    at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:340)
    at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:326)
    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
    at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:340)
    at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:326)
    at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:155)
    at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:340)
    at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:326)
    at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785)
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:116)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:494)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:461)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:378)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:350)
    at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:101)
    at java.lang.Thread.run(Unknown Source)

そしてここにコードがあります

public class redisdb {
    Jedis jedis;

    public redisdb() {
        jedis = new Jedis("192.168.56.101", 6179);
    }

    public void query() {

        jedis.append("foo", "bar"); 

    }
}
4

2 に答える 2

0

スレッドセーフな JedisPool が必要です。また、Java7 を使用している場合は、最新バージョンで Jedis クラスが Closable を実装しているため、try-with-resource を使用できます。

于 2015-01-21T06:26:39.450 に答える