/Users/carlosballock/node_modules/redis/index.js:582
throw err;
^
TypeError: Cannot call method 'split' of undefined
at /Users/carlosballock/node_modules/redis-cluster/index.js:42:30
at try_callback (/Users/carlosballock/node_modules/redis/index.js:579:9)
at RedisClient.return_reply (/Users/carlosballock/node_modules/redis/index.js:664:13)
at HiredisReplyParser. (/Users/carlosballock/node_modules/redis/index.js:312:14)
at HiredisReplyParser.EventEmitter.emit (events.js:95:17)
at HiredisReplyParser.execute (/Users/carlosballock/node_modules/redis/lib/parser/hiredis.js:43:18)
at RedisClient.on_data (/Users/carlosballock/node_modules/redis/index.js:535:27)
at Socket. (/Users/carlosballock/node_modules/redis/index.js:91:14)
at Socket.EventEmitter.emit (events.js:95:17)
at Socket. (_stream_readable.js:746:14)
The following is the result of calling "cluster nodes" in my cluster in 2 moments:
Shouldn't the "connectToNodesOfCluster" function be like this? (refer to the FIXME comments below)
function connectToNodesOfCluster (firstLink, callback) {
var redisLinks = [];
var fireStarter = connectToLink(firstLink);
fireStarter.cluster('nodes', function(err, nodes) {
if (err) {
callback(err, null);
return;
}
var lines = nodes.split('\n');
var n = lines.length -1;
while (n--) {
var items = lines[n].split(' ');
var name = items[0];
var flags = items[2];
var link = ( flags === 'myself' || flags === 'myself,master') ? firstLink : items[1];
var linkState = items[7]; // FIXME: this index was incremented;
if (lines.length === 1 && lines[1] === '') {
var slots = [0, 16383]
} else {
var slots = items[8].split('-'); // FIXME: this index was also incremented;
}
console.log(linkState);
if (linkState === 'connected') {
redisLinks.push({name: name, link: connectToLink(link), slots: slots});
}
if (n === 0) {
console.log(redisLinks);
callback(err, redisLinks);
}
}
});
}
In both of these moments, the same error occurred. Please, can you help me with that?
Regards,
Hi, João, I am trying to connect to a redis cluster (version 2.9.11) and I have the following error:
iMac-de-Carlos:loudspotter-node carlosballock$ sudo node server.js
/Users/carlosballock/node_modules/redis/index.js:582 throw err; ^ TypeError: Cannot call method 'split' of undefined at /Users/carlosballock/node_modules/redis-cluster/index.js:42:30 at try_callback (/Users/carlosballock/node_modules/redis/index.js:579:9) at RedisClient.return_reply (/Users/carlosballock/node_modules/redis/index.js:664:13) at HiredisReplyParser. (/Users/carlosballock/node_modules/redis/index.js:312:14)
at HiredisReplyParser.EventEmitter.emit (events.js:95:17)
at HiredisReplyParser.execute (/Users/carlosballock/node_modules/redis/lib/parser/hiredis.js:43:18)
at RedisClient.on_data (/Users/carlosballock/node_modules/redis/index.js:535:27)
at Socket. (/Users/carlosballock/node_modules/redis/index.js:91:14)
at Socket.EventEmitter.emit (events.js:95:17)
at Socket. (_stream_readable.js:746:14)
The following is the result of calling "cluster nodes" in my cluster in 2 moments:
1) Moment 1: 8e9910e26febc9a2122c03f62beee4d589436b24 :0 myself,master - 0 0 0 connected
2) Moment 2:
dd6e13b627a9b54337ec4718119ebddb99902cb0 127.0.0.1:6381 master - 0 1381638532662 0 connected 10922-16383 8e9910e26febc9a2122c03f62beee4d589436b24 :0 myself,master - 0 0 0 connected 0-5460 349630e9c51ae4b41aefdbab2511644b3512dc1d 127.0.0.1:6380 master - 0 1381638532662 0 connected 5461-10921
Shouldn't the "connectToNodesOfCluster" function be like this? (refer to the FIXME comments below)
function connectToNodesOfCluster (firstLink, callback) { var redisLinks = []; var fireStarter = connectToLink(firstLink); fireStarter.cluster('nodes', function(err, nodes) { if (err) { callback(err, null); return; } var lines = nodes.split('\n'); var n = lines.length -1; while (n--) { var items = lines[n].split(' '); var name = items[0]; var flags = items[2]; var link = ( flags === 'myself' || flags === 'myself,master') ? firstLink : items[1]; var linkState = items[7]; // FIXME: this index was incremented; if (lines.length === 1 && lines[1] === '') { var slots = [0, 16383] } else { var slots = items[8].split('-'); // FIXME: this index was also incremented; } console.log(linkState); if (linkState === 'connected') { redisLinks.push({name: name, link: connectToLink(link), slots: slots}); } if (n === 0) { console.log(redisLinks); callback(err, redisLinks); } } }); }
In both of these moments, the same error occurred. Please, can you help me with that? Regards,
Carlos.