Added ability to use redis datastores for session data
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
2022-11-05 16:14:37 -04:00
parent 4a43aaabb6
commit 0818f57131
5 changed files with 206 additions and 1 deletions

31
src/redis.js Normal file
View 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;
};