Redisson中设置值的key和分布式锁的key一样导致的异常

最近公司使用 Redisson封装的工具类替换之前的JRedis工具类,项目放在服务器上数据存操作没有问题,在取数据操作的时候一直出现以下错误:

[redisson-netty-2-9] 12:08:11.671 ERROR o.r.client.handler.CommandDecoder - Unable to decode data. 
channel: [id: 0xa7cd9836, L:/x.x.x.x - R:x.x.x.x], reply: ReplayingDecoderByteBuf(ridx=3751, widx=3751), command: (GET),
 params: [xxxxxx] java.io.IOException:
java.lang.NullPointerException at org.nustaq.serialization.FSTObjectInput.readObject(FSTObjectInput.java:247) at org.redisson.codec.FstCodec$1.decode(FstCodec.java:242) at org.redisson.client.handler.CommandDecoder.decode(CommandDecoder.java:384) 
at org.redisson.client.handler.CommandDecoder.decodeCommand(CommandDecoder.java:215) 
at org.redisson.client.handler.CommandDecoder.decode(CommandDecoder.java:153) 
at org.redisson.client.handler.CommandDecoder.decode(CommandDecoder.java:122) 
at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:489) 
at io.netty.handler.codec.ReplayingDecoder.callDecode(ReplayingDecoder.java:367) 
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:265) 
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) 
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) 
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) 
at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) 
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) 
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) 
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) 
at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) 
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) 
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) 
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) 
at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) 
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) 
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) 
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434) 
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) 
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) 
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965) 
at io.netty.channel.kqueue.AbstractKQueueStreamChannel$KQueueStreamUnsafe.readReady(AbstractKQueueStreamChannel.java:551) 
at io.netty.channel.kqueue.AbstractKQueueChannel$AbstractKQueueUnsafe.readReady(AbstractKQueueChannel.java:399) 
at io.netty.channel.kqueue.KQueueEventLoop.processReady(KQueueEventLoop.java:195) 
at io.netty.channel.kqueue.KQueueEventLoop.run(KQueueEventLoop.java:269)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:886) 
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) 
at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.NullPointerException: null 
at org.nustaq.serialization.FSTObjectInput.readObjectWithHeader(FSTObjectInput.java:357) 
at org.nustaq.serialization.FSTObjectInput.readObjectInternal(FSTObjectInput.java:331) 
at org.nustaq.serialization.FSTObjectInput.readObject(FSTObjectInput.java:311) 
at org.nustaq.serialization.FSTObjectInput.readObject(FSTObjectInput.java:245) 
... 
34 common frames omitted

从错误日志中看,刚开始一直认为是封装的工具类存在序列化问题,工具类在本地测试存取数据没有问题,后面将查询的key通过日志打印出来,通过用命令在Redis服务器上查看key到底是什么样的数据?
key是用hset存储的,所以查看key的数据为:

>hgetall examplekey
1) "01a6d806-d282-4715-9bec-f51b9aa98110:1"
2) "1"

另外同事说这个key 的ttl会一直变,从100到90,又到100.心想没有存这样的数据,另外ttl也对不上,后面注意到代码里面分布式锁生成key的方法和存储数据的key的方法一样,结合之前的ttl的变化,大概可以确认这个key是一个锁的key信息,锁的key值为"1",另外也确认了上面的解码的错误,是由于这个原因导致的,查到这个问题大概花费了4个小时左右。

添加新评论