Skip to content

use RedisCommands<String, byte[]> zadd set member string Exception #3267

Closed as not planned
@xiaoliefengfeng

Description

@xiaoliefengfeng

Bug Report

io.netty.handler.codec.EncoderException: Cannot encode command. Please close the connection as the connection state may be out of sync.
	at io.lettuce.core.protocol.CommandEncoder.encode(CommandEncoder.java:96)
	at io.lettuce.core.protocol.CommandEncoder.encode(CommandEncoder.java:78)
	at io.netty.handler.codec.MessageToByteEncoder.write(MessageToByteEncoder.java:107)
	at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:717)
	at io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:709)
	at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:792)
	at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:702)
	at io.lettuce.core.protocol.CommandHandler.writeSingleCommand(CommandHandler.java:421)
	at io.lettuce.core.protocol.CommandHandler.write(CommandHandler.java:387)
	at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:717)
	at io.netty.channel.AbstractChannelHandlerContext.invokeWriteAndFlush(AbstractChannelHandlerContext.java:764)
	at io.netty.channel.AbstractChannelHandlerContext$WriteTask.run(AbstractChannelHandlerContext.java:1071)
	at io.netty.util.concurrent.AbstractEventExecutor.safeExecute$$$capture(AbstractEventExecutor.java:164)
	at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java)
	at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:469)
	at io.netty.channel.kqueue.KQueueEventLoop.run(KQueueEventLoop.java:293)
	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)
	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.ClassCastException: class java.lang.String cannot be cast to class [B (java.lang.String and [B are in module java.base of loader 'bootstrap')
	at io.lettuce.core.codec.ByteArrayCodec.encodeValue(ByteArrayCodec.java:28)
	at io.lettuce.core.codec.ComposedRedisCodec.encodeValue(ComposedRedisCodec.java:58)
	at io.lettuce.core.protocol.CommandArgs$ValueArgument.encode(CommandArgs.java:742)
	at io.lettuce.core.protocol.CommandArgs.encode(CommandArgs.java:362)
	at io.lettuce.core.protocol.Command.encode(Command.java:126)
	at io.lettuce.core.protocol.AsyncCommand.encode(AsyncCommand.java:185)
	at io.lettuce.core.protocol.CommandEncoder.encode(CommandEncoder.java:93)
	... 19 common frames omitted

Current Behavior

Stack trace
io.lettuce.core.RedisCommandTimeoutException: Command timed out after 10 second(s)
	at io.lettuce.core.internal.ExceptionFactory.createTimeoutException(ExceptionFactory.java:59)
	at io.lettuce.core.internal.Futures.awaitOrCancel(Futures.java:246)
	at io.lettuce.core.FutureSyncInvocationHandler.handleInvocation(FutureSyncInvocationHandler.java:75)
	at io.lettuce.core.internal.AbstractInvocationHandler.invoke(AbstractInvocationHandler.java:80)
	at com.sun.proxy.$Proxy34.set(Unknown Source)
	at com.elex.billion.icefire.core.redis.UnRedisSession.set(UnRedisSession.java:191)
	at GMOtherScript.testRedis(GMOtherScript.java:549)
	at GMOtherScript.action(GMOtherScript.java:130)

Input Code

Input Code
public Long zadd(String key, double score, String member) {
        long beginTime = System.currentTimeMillis();
        Long rt = null;
        try {
            rt = getRedis().getCommands().zadd(getKey(key), score, (member));
            long diff = System.currentTimeMillis() - beginTime;
            if (diff > DIFFINT) {
                logger.info("zadd redis : " + getRedis().getInfo() + " slow cost : " + diff + " key:" + key);
            }
            return rt;
        } catch (Throwable e) {
            logger.info("zadd {} {}", getRedis().getInfo(), key, e);
        }
        return rt;
    }

Expected behavior/code

use RedisCommands<String, byte[]> .zadd(getKey(key), score, (member)), member is string ,now Caused by: java.lang.ClassCastException: class java.lang.String cannot be cast to class [B (java.lang.String, 调用其他方法的时候就会出现超时问题

Environment

  • Lettuce version(s): [e.g. 5.0.0.RELEASE, 4.2.2.Final]
  • Redis version: [e.g. 4.0.9]

Possible Solution

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: feedback-reminderWe've sent a reminder that we need additional information before we can continuestatus: waiting-for-feedbackWe need additional information before we can continue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions