Skip to content

Commit

Permalink
replaces error log with event emission when not connected to redis
Browse files Browse the repository at this point in the history
  • Loading branch information
niall3rs committed Feb 28, 2020
1 parent 0bd5eea commit 3de9832
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
9 changes: 6 additions & 3 deletions lib/persistence.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
var logging = require('minilog')('persistence'),
ConnectionHelper = require('./connection_helper.js'),
EventEmitter = require('events'),
// defaults
connection = {},
connected = false,
connecting = false,
configuration = {};

const Persistence = { }
const Persistence = {
emitter: new EventEmitter()
};

Persistence.connect = function(done) {
if (!connected) {
Expand All @@ -33,7 +36,7 @@ Persistence.redis = function(value) {
connection.client = value;
}
if(!connection.client || connection.subscriber.status !== 'ready') {
logging.error('Client: Not connected to redis');
this.emitter.emit('clientNotConnected');
}
return connection.client;
};
Expand All @@ -43,7 +46,7 @@ Persistence.pubsub = function(value) {
connection.subscriber = value;
}
if(!connection.subscriber || connection.subscriber.status !== 'ready') {
logging.error('Pubsub: Not connected to redis');
this.emitter.emit('pubsubNotConnected');
}
return connection.subscriber;
};
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
"glob": "7.0.5"
},
"dependencies": {
"ioredis": "^4.14.1"
"ioredis": "^4.16.0"
}
}

0 comments on commit 3de9832

Please sign in to comment.