Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"use strict";
const Redis = require("ioredis");
const MyService = require("path/to/my/service");
// Create a custom connector that fetches sentinels from an external call
class AsyncSentinelConnector extends Redis.SentinelConnector {
constructor(options = {}) {
// Placeholder
options.sentinels = options.sentinels || [
{ host: "localhost", port: 6379 }
];
// SentinelConnector saves options as its property
super(options);
}
connect(eventEmitter) {
return MyService.getSentinels().then(sentinels => {
this.options.sentinels = sentinels;
this.sentinelIterator = new Redis.SentinelIterator(sentinels);
return Redis.SentinelConnector.prototype.connect.call(this, eventEmitter);
});
return MyService.getSentinels().then(sentinels => {
this.options.sentinels = sentinels;
this.sentinelIterator = new Redis.SentinelIterator(sentinels);
return Redis.SentinelConnector.prototype.connect.call(this, eventEmitter);
});
}