How to pass Redis connection to module?


Is Redis connection information available on globals? I want to pass that to a server connect extension/module

You need to require /app/config/config.js from your module.


If you want to use environment variables you need to change core files and make sure you discard changes with GIT with every update.


const config = require('./config');

if (config.redis) {
    const redis = require('redis');
    global.redisClient = redis.createClient(config.redis === true ? 'redis://redis' : process.env.REDIS_URL);

module.exports = global.redisClient;

This way I set redis to NO(unchecked) on the UI and load it from dotenv


Bummer about the core changes, looks the trio is very busy :slightly_frowning_face:

With Redis checkbox unchecked, does it still store Express sessions on Redis? I’m guessing it won’t, because config.redis is false

It does. No problems there as it will read the global.redisClient data which was set above.

if ($type == 'redis') { //
        const RedisStore = require('connect-redis')(session); = new RedisStore(Object.assign({
            client: global.redisClient

Just make sure you have the right config in config.js

"session": {
        "store": {
            "$type": "redis",
            "ttl": 86400

If you deviate from core and use ENV variables you require dotenv and if not you require config.js