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

Ensure node exists before being redirected via an ASK #341

Merged
merged 1 commit into from
Jun 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/cluster/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,8 @@ Cluster.prototype.sendCommand = function (command, stream, node) {
},
ask: function (slot, key) {
debug('command %s is required to ask %s:%s', command.name, key);
var splitKey = key.split(':');
_this.connectionPool.findOrCreate({ host: splitKey[0], port: Number(splitKey[1]) });
tryConnection(false, key);
},
tryagain: partialTry,
Expand Down
32 changes: 32 additions & 0 deletions test/functional/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,38 @@ describe('cluster', function () {
cluster.get('foo');
});
});

it('should be able to redirect a command to a unknown node', function (done) {
var asked = false;
var slotTable = [
[0, 16383, ['127.0.0.1', 30002]]
];
var node1 = new MockServer(30001, function (argv) {
if (argv[0] === 'get' && argv[1] === 'foo') {
expect(asked).to.eql(true);
return "bar"
} else if (argv[0] === 'asking') {
asked = true;
}
});
var node2 = new MockServer(30002, function (argv) {
if (argv[0] === 'cluster' && argv[1] === 'slots') {
return slotTable;
}
if (argv[0] === 'get' && argv[1] === 'foo') {
return new Error('ASK ' + calculateSlot('foo') + ' 127.0.0.1:30001');
}
});

var cluster = new Redis.Cluster([
{ host: '127.0.0.1', port: '30002' }
]);
cluster.get('foo', function (err, res) {
expect(res).to.eql('bar');
cluster.disconnect();
disconnect([node1, node2], done);
});
});
});

describe('TRYAGAIN', function () {
Expand Down