Skip to content

Commit

Permalink
Merge pull request #284 from kcarlson/aws-auto-discovery
Browse files Browse the repository at this point in the history
Support for 'config get cluster'
  • Loading branch information
Ron Korving committed May 17, 2016
2 parents b2a4bd5 + 59172b6 commit 7d6683f
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions lib/memcached.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ Client.config = {
if(!server.match(/(.+):(\d+)$/)) {
server = server + ':11211';
}

// server is dead, bail out
if (server in this.issues && this.issues[server].failed) {
return callback(false, false);
Expand Down Expand Up @@ -565,6 +565,11 @@ Client.config = {

return [BUFFER, false];
}
// Amazon-specific memcached configuration information, used for node
// auto-discovery.
, 'CONFIG': function() {
return [CONTINUE, this.bufferArray[0]];
}
};

function resultSetIsEmpty(resultSet) {
Expand Down Expand Up @@ -706,9 +711,21 @@ Client.config = {
token = S.bufferArray.shift();
tokenSet = token.split(' ');

// special case for digit only's these are responses from INCR and DECR
if (/^\d+$/.test(tokenSet[0])) tokenSet.unshift('INCRDECR');

if (/^\d+$/.test(tokenSet[0])) {
// special case for "config get cluster"
// Amazon-specific memcached configuration information, see aws
// documentation regarding adding auto-discovery to your client library.
// Example response of a cache cluster containing three nodes:
// configversion\n
// hostname|ip-address|port hostname|ip-address|port hostname|ip-address|port\n\r\n
if (/(([-.a-zA-Z0-9]+)\|(\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b)\|(\d+))/.test(S.bufferArray[0])) {
tokenSet.unshift('CONFIG');
}
// special case for digit only's these are responses from INCR and DECR
else {
tokenSet.unshift('INCRDECR');
}
}
// special case for value, it's required that it has a second response!
// add the token back, and wait for the next response, we might be
// handling a big ass response here.
Expand Down

0 comments on commit 7d6683f

Please sign in to comment.