Added ability to use redis datastores for session data
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
31
src/redis.js
Normal file
31
src/redis.js
Normal file
@ -0,0 +1,31 @@
|
||||
const redisConfig = require('config').get('redis');
|
||||
|
||||
exports.default = function() {
|
||||
let redisUrl = 'redis://';
|
||||
|
||||
// add the redis username if defined
|
||||
if (typeof redisConfig.get('username') !== 'undefined') {
|
||||
redisUrl += redisConfig.get('username');
|
||||
}
|
||||
// add the user password if defined
|
||||
if (typeof redisConfig.get('password') !== 'undefined') {
|
||||
redisUrl += ':' + redisConfig.get('password') + '@';
|
||||
}
|
||||
// add redis host URL
|
||||
redisUrl += redisConfig.get('host');
|
||||
// add redis host port
|
||||
redisUrl += ':' + redisConfig.get('port');
|
||||
// add redis database number if defined
|
||||
if (typeof redisConfig.get('number') !== 'undefined') {
|
||||
redisUrl += redisConfig.get('number');
|
||||
}
|
||||
|
||||
const { createClient } = require("redis");
|
||||
let redisClient = createClient({
|
||||
url: redisUrl,
|
||||
legacyMode: true,
|
||||
});
|
||||
redisClient.connect().catch(console.error);
|
||||
|
||||
return redisClient;
|
||||
};
|
Reference in New Issue
Block a user