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

lua function not execute on readonly slave node #197

Closed
nichliu opened this issue Nov 23, 2015 · 4 comments
Closed

lua function not execute on readonly slave node #197

nichliu opened this issue Nov 23, 2015 · 4 comments

Comments

@nichliu
Copy link

nichliu commented Nov 23, 2015

I noticed lua function not execute on readonly slave node
I used redis.defineCommand to define the lua function

I defined readonly nodes during the connection.

Redis 3.05 cluster

@luin
Copy link
Collaborator

luin commented Nov 23, 2015

Could you please post your code here that can reproduce the problem?

@nichliu
Copy link
Author

nichliu commented Nov 23, 2015

var Redis = require('ioredis');

var r1 = "x.x.x.x";
var r1s = "x.x.x.x";
var r2 = "x.x.x.x";
var r2s = "x.x.x.x";
var r3 = "x.x.x.x";
var r3s = "x.x.x.x";
var r4 = "x.x.x.x";
var r4s = "x.x.x.x";

var redisNodes= [{
    port: 6379,
    host: r1
},{
    port: 6379,
    host: r2
},{
    port: 6379,
    host: r3
},{
    port:6379,
    host:r4
},{
    port:6379,
    host:r4s,
    readOnly: true
},{
    port:6379,
    host:r1s,
    readOnly: true
},{
    port:6379,
    host:r2s,
    readOnly: true
},{
    port:6379,
    host:r3s,
    readOnly: true
}];

var redis = new Redis.Cluster(redisNodes);

redis.defineCommand('calc', {
    numberOfKeys: 1,
    lua: '.....lua code'
});

redis.calc(key,start,end,screen,function(err,data){
    #process result or err
})

@luin
Copy link
Collaborator

luin commented Nov 23, 2015

The readOnly option should be defined in the second parameter:

var cluster = new Redis.Cluster(nodes, { readOnly: true });

This option means every command sent from the cluster instance is readonly so that ioredis will send them to both masters and slaves instead of just masters in order to scale reads and writes.

I understand you intention that sending readonly commands to slaves and others to masters. This feature has been discussed in #170 and will be implemented in ioredis v2.0.

@nichliu
Copy link
Author

nichliu commented Nov 23, 2015

Thx. I got it.

@luin luin closed this as completed Nov 24, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants