Callback called only once + database selection
This commit is contained in:
parent
a3963485f5
commit
028049f8b2
|
@ -27,7 +27,21 @@ exports.initialize = function initializeSchema(schema, callback) {
|
|||
schema.settings.options
|
||||
);
|
||||
schema.client.auth(schema.settings.password);
|
||||
schema.client.on('connect', callback);
|
||||
var callbackCalled = false;
|
||||
var database = schema.settings.hasOwnProperty('database') && schema.settings.database;
|
||||
schema.client.on('connect', function () {
|
||||
if (!callbackCalled && database === false) {
|
||||
callbackCalled = true;
|
||||
callback();
|
||||
} else if (database !== false) {
|
||||
if (callbackCalled) {
|
||||
return schema.client.select(schema.settings.database);
|
||||
} else {
|
||||
callbackCalled = true;
|
||||
return schema.client.select(schema.settings.database, cb);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
schema.adapter = new BridgeToRedis(schema.client);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue