From 94f823fa27adf989ca8f1084473bad509311023d Mon Sep 17 00:00:00 2001 From: Ben West Date: Fri, 25 Sep 2020 16:41:45 -0700 Subject: [PATCH] Allow passing redis connection settings via urlish This facilitates passing redis authentication parameters such as username and password from the runtime environment to redis. redis-sessions looks for o.options.url, which is capable of passing most parameters in one string. If RS_REDISURL environment variable exists, it will override the RS_REDISHOST and RS_REDISPORT variables. Ability to pass these parameters is required to connect to any managed redis providers. --- app.coffee | 6 ++++++ app.js | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/app.coffee b/app.coffee index 39a056e..5f1794a 100644 --- a/app.coffee +++ b/app.coffee @@ -17,6 +17,12 @@ redisconfig = port: parseInt(process.env.RS_REDISPORT or 6379, 10) namespace: process.env.RS_NAMESPACE or "rs" loglevel = process.env.RS_LOGLEVEL or "dev" +if process.env.RS_REDISURL + redisconfig = + namespace: process.env.RS_NAMESPACE or "rs" + options: + url: process.env.RS_REDISURL + RedisSessions = require "redis-sessions" diff --git a/app.js b/app.js index 22d360c..c1c5dcc 100644 --- a/app.js +++ b/app.js @@ -22,6 +22,15 @@ redisconfig = { loglevel = process.env.RS_LOGLEVEL || "dev"; +if (process.env.RS_REDISURL) { + redisconfig = { + namespace: process.env.RS_NAMESPACE || "rs", + options: { + url: process.env.RS_REDISURL + } + }; +} + RedisSessions = require("redis-sessions"); rs = new RedisSessions(redisconfig);