-
Notifications
You must be signed in to change notification settings - Fork 226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow more REDIS settings #1765
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,20 @@ const AppSettingsSchema = mongoose.Schema( | |
type: Number, | ||
default: "6379", | ||
}, | ||
redisUser: { | ||
type: String, | ||
}, | ||
redisPassword: { | ||
type: String, | ||
}, | ||
redisDb: { | ||
type: Number, | ||
default: 0 | ||
}, | ||
redisPrefix: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this prefix for? |
||
type: String, | ||
default: "", | ||
}, | ||
jwtTTL: { | ||
type: String, | ||
required: true, | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -108,10 +108,21 @@ const shutdown = async () => { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const settings = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ServiceRegistry.get(SettingsService.SERVICE_NAME).getSettings() || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const { redisHost = "127.0.0.1", redisPort = 6379 } = settings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
redisHost = "127.0.0.1", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
redisPort = 6379, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
redisUser = null, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
redisPassword = null, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
redisDb = 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
redisPrefix = "" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} = settings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const redis = new IORedis({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
host: redisHost, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
port: redisPort, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
username: redisUser, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
password: redisPassword, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
db: redisDb, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
keyPrefix: redisPrefix, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
119
to
126
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add error handling for Redis connection. The Redis connection should handle potential connection errors and authentication failures. const redis = new IORedis({
host: redisHost,
port: redisPort,
username: redisUser,
password: redisPassword,
db: redisDb,
keyPrefix: redisPrefix,
+ retryStrategy(times) {
+ const delay = Math.min(times * 50, 2000);
+ return delay;
+ }
});
+
+redis.on('error', (err) => {
+ logger.error({
+ message: 'Redis connection error',
+ error: err.message,
+ service: SERVICE_NAME,
+ method: 'shutdown'
+ });
+}); 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
logger.info({ message: "Flushing Redis" }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
await redis.flushall(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,10 +28,21 @@ class NewJobQueue { | |
Worker | ||
) { | ||
const settings = settingsService.getSettings() || {}; | ||
const { redisHost = "127.0.0.1", redisPort = 6379 } = settings; | ||
const { | ||
redisHost = "127.0.0.1", | ||
redisPort = 6379, | ||
redisUser = null, | ||
redisPassword = null, | ||
redisDb = 0, | ||
redisPrefix = "" | ||
} = settings; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will all potentially compatible redis-like databases work with these null and empty values? If not or you don't know, then why not start with just Host and Port, and conditionally add other properties if they have been specified. |
||
const connection = { | ||
host: redisHost, | ||
port: redisPort, | ||
username: redisUser, | ||
password: redisPassword, | ||
db: redisDb, | ||
keyPrefix: redisPrefix, | ||
}; | ||
|
||
this.queues = {}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Ensure proper type conversion for Redis database number.
The
redisDb
value should be converted to a number before sending to the server.📝 Committable suggestion