Skip to content
Browse files

Added redisConfig var; method to extract redis password from config; …

…authenticate to Redis on connection.
  • Loading branch information...
1 parent c00e3e5 commit 3ab48bf857e30cecf686f16ace726dc8945259a5 @joemccann joemccann committed Dec 6, 2011
Showing with 25 additions and 1 deletion.
  1. +25 −1 app.js
View
26 app.js
@@ -24,6 +24,8 @@ var appConfig = JSON.parse(fs.readFileSync(__dirname + '/app.json', 'UTF-8'))
var githubConfig = JSON.parse(fs.readFileSync(__dirname + '/config/github.json', 'UTF-8'))
+var redisConfig = fs.readFileSync(__dirname + '/config/redis.conf', 'UTF-8')
+
var dillingerReadme = fs.readFileSync(__dirname + '/README.md', 'UTF-8')
@@ -528,6 +530,21 @@ function setStylusImagePrefix(productionFile){
}
+// Snatch the pw from the redis config file.
+function findRedisPassword(){
+
+ var pw = ''
+
+ // bet you didn't know you could do that with String#replace(), eh?
+ redisConfig.replace(/(masterauth+\s)+(.*)+\s/, function( line, masterauthString, password){
+ pw = password
+ })
+
+ return pw
+
+}
+
+
function initRedis(){
redisClient = redis.createClient()
@@ -536,7 +553,14 @@ function initRedis(){
console.log("Redis connection error to " + redisClient.host + ":" + redisClient.port + " - " + err);
});
- redisClient.on("connect", function (err){});
+ redisClient.on("connect", function (err){
+ if(err) throw err
+ else{
+ redisClient.auth(findRedisPassword(), function(){
+ debug && console.log('Authenticated to redis.')
+ })
+ }
+});
RedisStore = require('connect-redis')(express);

0 comments on commit 3ab48bf

Please sign in to comment.
Something went wrong with that request. Please try again.