Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HMGET proxy not working as expected #627

Closed
moores-expedia opened this issue Oct 11, 2017 · 3 comments
Closed

HMGET proxy not working as expected #627

moores-expedia opened this issue Oct 11, 2017 · 3 comments
Labels
type: bug A general bug
Milestone

Comments

@moores-expedia
Copy link

moores-expedia commented Oct 11, 2017

Using latest 5.0.0.RELEASE:
I am providing a command interface and a class that fails with "ERR wrong number of arguments for 'hmget' command" on an empty redis instance for the HMGET command when the method signature is as specified below. Fixed hmget field parameters work fine, but when i use vargs or an Iterable, looks like the fields are not passed in to redis.

Exception/trace here:

Caused by: io.lettuce.core.RedisCommandExecutionException: ERR wrong number of arguments for 'hmget' command
	at io.lettuce.core.protocol.AsyncCommand.completeResult(AsyncCommand.java:116)
	at io.lettuce.core.protocol.AsyncCommand.complete(AsyncCommand.java:107)
	at io.lettuce.core.protocol.CommandHandler.decode(CommandHandler.java:513)
	at io.lettuce.core.protocol.CommandHandler.channelRead(CommandHandler.java:485)
	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)

INTERFACE:

package lettuce;

import io.lettuce.core.RedisFuture;
import io.lettuce.core.dynamic.Commands;
import io.lettuce.core.dynamic.batch.BatchExecutor;
import io.lettuce.core.dynamic.batch.CommandBatching;

import java.util.List;
import java.util.Map;
import java.util.Set;

public interface JavaPropertyCommands extends Commands, BatchExecutor {
    RedisFuture<List<byte[]>> hmget(CommandBatching batching, byte[] key, List<byte[]> fields);
} 

CALL THROUGH INTERFACE:

package lettuce;
import io.lettuce.core.RedisClient;
import io.lettuce.core.RedisFuture;
import io.lettuce.core.RedisURI;
import io.lettuce.core.api.StatefulRedisConnection;
import io.lettuce.core.codec.ByteArrayCodec;
import io.lettuce.core.dynamic.RedisCommandFactory;
import io.lettuce.core.dynamic.batch.CommandBatching;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

public class HmgetTest {

    public void callHmget() throws Exception {

        RedisClient client = RedisClient.create();
        RedisURI uri = RedisURI.create("redis://localhost:6379");
        StatefulRedisConnection<byte[], byte[]> connection =  client.connect(new ByteArrayCodec(), uri);
        RedisCommandFactory factory = new RedisCommandFactory(connection);
        JavaPropertyCommands commands = factory.getCommands(JavaPropertyCommands.class);

        byte[] key = "key".getBytes();
        List<byte[]> fields = new ArrayList<>();
        fields.add("f1".getBytes());
        fields.add("f2".getBytes());

        RedisFuture<List<byte[]>> f = commands.hmget(CommandBatching.flush(), key, fields);

        List<byte[]> answer = f.get(2, TimeUnit.SECONDS);
        System.out.println(answer);
    }
}
@mp911de mp911de added the type: bug A general bug label Oct 12, 2017
@mp911de
Copy link
Collaborator

mp911de commented Oct 12, 2017

Thanks a lot for the example. I can reproduce the issue which is related to byte[]. byte[] elements of an Iterable were not bound.

You can view the sent commands from the client perspective by enabling TRACE logging for io.lettuce.core.protocol. This will create a lot of logging and slows the system down – not suitable for production but handy for development.

@mp911de mp911de added this to the Lettuce 5.0.1 milestone Oct 12, 2017
mp911de added a commit that referenced this issue Oct 12, 2017
Byte arrays passed within an Iterable are now unrolled and bound correctly. Previously, byte arrays were not bound and silently dropped.
mp911de added a commit that referenced this issue Oct 12, 2017
Improve null-handling of KeyList/Map outputs. Report command name via StringCommandType.
mp911de added a commit that referenced this issue Oct 12, 2017
Byte arrays passed within an Iterable are now unrolled and bound correctly. Previously, byte arrays were not bound and silently dropped.
mp911de added a commit that referenced this issue Oct 12, 2017
Improve null-handling of KeyList/Map outputs. Report command name via StringCommandType.
@mp911de
Copy link
Collaborator

mp911de commented Oct 12, 2017

That's fixed now and available via 5.0.1.BUILD-SNAPSHOT.

@mp911de mp911de closed this as completed Oct 12, 2017
@moores-expedia
Copy link
Author

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants