3rd-Eden / memcached

A fully featured Memcached client build on top of Node.js. Build with scaling in mind so it will support Memcached clusters and consistent hashing.
MIT License
1.31k stars 276 forks source link

Connecting always to 127.0.0.1 when different IP is provided #323

Open amit-mn opened 6 years ago

amit-mn commented 6 years ago

Memcache not connecting to IP which is provided to connection string like below:

var Memcached = require('memcached');
var memcached = new Memcached();
memcached.connect( '12.34.567.890:11211', function( err, conn ){
  if( err ) {
     console.log(err);
  }
});

When I provide above IP (dummy IP : 12.34.567.890) or any other in connection string then It try to connect only to 127.0.0.1 IP. That's why it is not connecting to particular IP.

For this I have to set the desired IP in it's library file :

project_dir/node_modules/memcached/lib/memcached.js

var servers = []
    , weights = {}
    , regular = 'localhost:11211'      //<------- here I have to change localhost to my IP then it works
    , key;

And I think it is not a good idea. Because I want dynamic connections in my project to connect different-2 memcached servers. So it is not possible to change the above setting every time.

Is there a way to resolve this issue?

mapleeit commented 6 years ago

At first, I don't recommend using memcached.connect. It's a private method not public API. Second, if you provide a dummy IP, which can't be validated, it will use the default IP (localhost:11211). So try to use a normal IP.