mosca
mosca copied to clipboard
Connecting to Remote Redis Server
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:[email protected]: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?
can you add the full stacktrace?
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)
Proposing fix here https://github.com/mcollina/mosca/pull/630