Skip to content
This repository has been archived by the owner on Feb 11, 2020. It is now read-only.

Connecting to Remote Redis Server #626

Open
ccravens opened this issue Mar 30, 2017 · 3 comments
Open

Connecting to Remote Redis Server #626

ccravens opened this issue Mar 30, 2017 · 3 comments

Comments

@ccravens
Copy link

Pouring through documentation, examples and even the Mosca source for a couple of days now, and have not been able to successfully connect to a remote redis server that requires authentication. I have the following Redis connection URL:

redis://username:password@redis.server.com:9999

and the following documentation specifies the options I have: http://www.mosca.io/docs/lib/persistence/redis.js.html#RedisPersistence

And this is my code:

  var redisurl = url.parse(config['redis'].url, true, true);
  var username = '';
  var password = '';
  if(redisurl.auth != null) {
    username = redisurl.auth.split(':')[0];
    password = redisurl.auth.split(':')[1];
  }
  var server = new mosca.Server({
    backend: {
      type: 'redis',
      redis: require('redis'),
      password: password,
      port: redisurl.port,
      host: redisurl.hostname,
      return_buffers: true // to handle binary payloads
    },
    persistence: {
      factory: mosca.persistence.Redis,
      host: redisurl.hostname,
      port: redisurl.port
    }
  }, function() {
    server.attachHttpServer(app);
  });

And here is what I get as a response:

/Users/ccravens/Business/ossys/Clients/SES/src/ses-proxy/node_modules/ioredis/node_modules/bluebird/js/main/async.js:43
        fn = function () { throw arg; };
                           ^

Error: Ready check failed: NOAUTH Authentication required

Am I missing something?

@mcollina
Copy link
Collaborator

can you add the full stacktrace?

@ccravens
Copy link
Author

ccravens commented Mar 31, 2017

Apologies, after removing the "db:12" attribute from the backend object, there is no stacktrace. It seems to just hang. I have a console statement on "ready" status:

  server.on('ready', function() {
    console.log('Mosca is Running');
    server.authenticate = function(client, username, password, cb) {
      cb(null, (username === '1' && password.toString('ascii') === '2'));
    };
  });

I never see "Mosca is Running" when attempting to connect to the remote server. However when I switch to a local Redis server everything works as expected.

--- edit ---

After running again, there was a stacktrace:

/Users/ccravens/Business/ossys/Clients/SES/src/ses-proxy/node_modules/ioredis/node_modules/bluebird/js/main/async.js:43
        fn = function () { throw arg; };
                           ^

Error: Ready check failed: NOAUTH Authentication required
    at /Users/ccravens/Business/ossys/Clients/SES/src/ses-proxy/node_modules/ioredis/lib/redis/event_handler.js:35:27
    at /Users/ccravens/Business/ossys/Clients/SES/src/ses-proxy/node_modules/ioredis/lib/redis.js:375:14
    at tryCatcher (/Users/ccravens/Business/ossys/Clients/SES/src/ses-proxy/node_modules/ioredis/node_modules/bluebird/js/main/util.js:26:23)
    at Promise.errorAdapter (/Users/ccravens/Business/ossys/Clients/SES/src/ses-proxy/node_modules/ioredis/node_modules/bluebird/js/main/nodeify.js:36:34)
    at Promise._settlePromiseAt (/Users/ccravens/Business/ossys/Clients/SES/src/ses-proxy/node_modules/ioredis/node_modules/bluebird/js/main/promise.js:582:21)
    at Promise._settlePromises (/Users/ccravens/Business/ossys/Clients/SES/src/ses-proxy/node_modules/ioredis/node_modules/bluebird/js/main/promise.js:700:14)
    at Async._drainQueue (/Users/ccravens/Business/ossys/Clients/SES/src/ses-proxy/node_modules/ioredis/node_modules/bluebird/js/main/async.js:123:16)
    at Async._drainQueues (/Users/ccravens/Business/ossys/Clients/SES/src/ses-proxy/node_modules/ioredis/node_modules/bluebird/js/main/async.js:133:10)
    at Immediate.Async.drainQueues [as _onImmediate] (/Users/ccravens/Business/ossys/Clients/SES/src/ses-proxy/node_modules/ioredis/node_modules/bluebird/js/main/async.js:15:14)
    at tryOnImmediate (timers.js:543:15)
    at processImmediate [as _immediateCallback] (timers.js:523:5)

@eljefedelrodeodeljefe
Copy link

Proposing fix here #630

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants