Getting EVAL/EVALSHA command to run on slave nodes

253 views
Skip to first unread message

migr...@gmail.com

unread,
Feb 15, 2017, 2:40:29 PM2/15/17
to lettuce-redis-client-users

Hi all,

I had a question specifically regarding this pull request: https://github.com/mp911de/lettuce/pull/366I am using the 4.3.1 shaded jar and am trying to get eval to run on the slaves, however it always ends up running on the master. 

See the below test code:

RedisClusterClient client = RedisClusterClient.create(RedisURI.create(hostname, 6380));
StatefulRedisClusterConnection<String, String>  conn = client.connect();
conn.setReadFrom(ReadFrom.SLAVE);

RedisAdvancedClusterCommands<String, String> sync = conn.sync();

sync.get("test");
sync.eval("return '1';", ScriptOutputType.VALUE, new String[]{"test"});

When I run this, I will see the get command run on the slave (port 6384). However, when the eval command is ran it will end up on the master (port 6381). 

I'm not too familiar with the Lettuce code, but when I was debugging the dispatching of the command it ended up in AbstractChannelHandlerContext:writeAndFlush. Inside the message there seemed to be an error

AsyncCommand [type=EVAL, output=ValueOutput [output=null, error='MOVED 6918 xx.xx.xx.xx:6381'], commandType=com.lambdaworks.redis.protocol.Command]

So it seems like it ends up retrying the eval command against the master node. Is there something else I need to change in order to be able to send eval commands to a slave node?

Thanks

migr...@gmail.com

unread,
Feb 15, 2017, 3:05:30 PM2/15/17
to lettuce-redis-client-users, migr...@gmail.com
After poking around a bit, I'm guessing it's related to this: https://github.com/antirez/redis/issues/3513.

Mark Paluch

unread,
Feb 16, 2017, 1:05:59 PM2/16/17
to lettuce-redis-client-users, migr...@gmail.com
Hi, 

the command is dispatched according to the host that handles the according slot. EVALSHA is allowed for read-commands so it's dispatched to a slave. The intermediate state you're seeing (MOVED …) is the slaves' response that causes a redirect to the master again. For now, it's a Redis issue. You can however reproduce the issue with redis-cli.

Cheers, 
Mark
Reply all
Reply to author
Forward
0 new messages